note 37726 added to keyword.extends

From: Date: Mon, 24 Nov 2003 18:56:05 +0000
Subject: note 37726 added to keyword.extends
Groups: php.notes 
Request: Send a blank email to php-notes+get-60917@lists.php.net to get a copy of this message
Typically you want to keep your scripts short and modular by including libraries of functions. However this does not work when defining classes. The below code doesn't work ---------------------------------------------------- //a.php class A{ function derp(){ return 'OI'; } include_once('alib.php'); } echo '<strong>testing...</strong><br /><br />'; $o = new A(); echo $o->derp() . '<BR />'; echo $o->bork() . '<BR />'; ---------------------------------------- //alib.php function bork(){ return 'captain planet'; } ---------------------------------------- The include cannot be in the class def. If you include with a method, the functions are in the scope of the script and not class methods. If this were to work, it would be a nifty hack to organize code, especially if you are working in a modular system. It might also be a very hacked way for multiple inheritance. Blaine Flynn Garrett http://artattack.to?zombie ---- Manual Page -- http://www.php.net/manual/en/keyword.extends.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37726 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37726&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37726&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60917) next »