|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-04-21 05:15 UTC] cpoirier at shelluser dot net
In file class.php:
--------------------------------------------------------
<?php
class myclass
{
require( $DOCUMENT_ROOT . "/methods.inc.php" );
}
$myinstance = new myclass;
$myinstance->method();
?>
--------------------------------------------------------
In file methods.inc.php:
--------------------------------------------------------
<?php
function method()
{
print "hi";
}
?>
--------------------------------------------------------
Accessing class.php returns the following error:
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in class.php on line 5
Surely this should work?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
Right. require() and include() both happen at run-time while the class is checked for method's at compile-time. You have to include the method definitions inside the class {} Andi