note 90068 added to language.oop5.autoload

From: Date: Sat, 04 Apr 2009 17:28:39 +0000
Subject: note 90068 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-152812@lists.php.net to get a copy of this message
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. ---- Server IP: 87.124.35.190 Probable Submitter: 78.86.242.149 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/90068 Del: integrated -- https://master.php.net/note/delete/90068/integrated Del: useless -- https://master.php.net/note/delete/90068/useless Del: bad code -- https://master.php.net/note/delete/90068/bad+code Del: spam -- https://master.php.net/note/delete/90068/spam Del: non-english -- https://master.php.net/note/delete/90068/non-english Del: in docs -- https://master.php.net/note/delete/90068/in+docs Del: other reasons-- https://master.php.net/note/delete/90068 Reject -- https://master.php.net/note/reject/90068 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152812) next »