note 90068 deleted from language.oop5.autoload by danbrown

From: Date: Sat, 04 Apr 2009 17:30:49 +0000
Subject: note 90068 deleted from language.oop5.autoload by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152817@lists.php.net to get a copy of this message
Note Submitter: roman dot drapeko at gmail dot com ---- 1. Generator of associations between classes and their locations. It's very simple to use. by typing "php auto_generator.php folderName" it will generate an array of associations between classes/interfaces and their locations. Sample is shown below. <? $generated_list = array ( 'classes' => array ( 'A' => array ('path' => 'ProjectClassesChildrenA.php', 'extends' => array (), 'implements' => array ('I1')), 'B' => array ('path' => 'ProjectClassesB.php', 'extends' => array (), 'implements' => array ('I2')), 'C' => array ('path' => 'ProjectClassesC.php', 'extends' => array ('B'), 'implements' => array ('I1', 'I3')), ), 'interfaces' => array ( 'I2' => array ('path' => 'ProjectInterfacesblablabla.php', 'extends' => array ('I1')), 'I1' => array ('path' => 'ProjectInterfacesI1.php', 'extends' => array ()), 'I3' => array ('path' => 'ProjectInterfacesI3.php', 'extends' => array ()), ), ); ?> It accepts several incoming parameters and it's very simple to use. It's also can be easily used as an basis of extended generators. You can download it and example of extended generator here http://wp.drapeko.com/store/php-autoloading-files/ . 2. Moreover you probably will be interested in article called Autoloading in PHP. It's available here http://wp.drapeko.com/2009/03/28/autoloading-in-php/ . Imagine that we have the following structure: Project ..Classes ....Children ......A.php class A implements I1 {} ....B.php class B implements I2 {} ....Class_C.php class C extends B implements I1, I3 {} ..Interfaces ....I1.php interface I1 {} ....blablabla.php interface I2 extends I1 {} ....I3.php interface I3 {} if you use <?php /** * first question */ function __autoload($className) { echo "1, "; require_once 'Project/Interfaces/I3.php'; echo "2, "; require_once 'Project/Classes/B.php'; echo "3, "; require_once 'Project/Classes/Children/A.php'; echo "4, "; require_once 'Project/Interfaces/I1.php'; echo "5, "; require_once 'Project/Interfaces/blablabla.php'; } $x = new A(); ?> Could you predict the result? The output is 1, 2, 1, 2, 3, 1, 2, 3, 4, 5, 4, 5, 3, 4, 5. Several other examples are considered in this article.

« previous php.notes (#152817) next »