Re: [PHP4BETA] Bug: Isn´t it possible to use require /include to add methods to classes????
| From: | Faisal Nasim | Date: | Fri, 12 May 2000 10:33:43 +0000 |
| Subject: | Re: [PHP4BETA] Bug: Isn´t it possible to use require /include to add methods to classes???? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-14893@lists.php.net to get a copy of this message | ||
| Hi,
|
| I tried to require/include (tried both) a file containg a simple
| function, which will be used in many different scripts/functions.
| This functions extends in this case several classes by an unique method,
| they all can use. I found out that it´s even uninteresting if the file
| really exists or not. No "file not found" error is thrown. Requiring
| from the main script, outside any classes works and if a file isn´t
| existent an error occurs.
|
| I got this error:
|
| Parse error: parse error, expecting
T_OLD_FUNCTION' or T_FUNCTION' or
| T_VAR' or '}'' in class.db.php on line 98
Are you trying to do something like this:
class X
{
include "etc.php";
}
Please keep this in mind that a class {} is not function {}. The
error says it pretty clear that it would expect a variable declaration,
an 'old_function' definition or a 'function' or simply a '}' which
ends
the class.
A possible workaround is that you remove the <? and ?> tags
from your 'include'd or 'require'd file, and do something like this:
<?
$x = join ( '' , "etc.php" );
eval ( '
class X
{
' . $x . '
function another_new_function ()
{
$this -> etc (); // $ doesn't need escaping!
// etc
}
}
' );
Intead of this, you better modify the overall design and pack
your class in a file and include()/require() it from the global
scope/function.
Enjoy!
Faisal