This is a discussion on Retrieving values from array on a class within the PHP General forums, part of the PHP Programming Forums category; Richard Lynch wrote: > But I don't think you can even *DO* an include() inside a class > definition, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Richard Lynch wrote:
> But I don't think you can even *DO* an include() inside a class > definition, so that should be giving you an error... You can do an include/require anywhere. However, you cannot declare new functions inside an include and use it to add methods or variables to a class. -->--inc.php-->-- <?php function foo() { return 'I pity to foo'; } --<-----------<-- -->--use.php-->-- <?php class bar { include('inc.php'); } $b = new bar(); print $b->foo(); // This will not work print foo(); // But this will --<-----------<-- This will not work! foo() is actually defined at the global scope. -Stut |