note 49142 added to language.oop5.autoload

From: Date: Tue, 18 Jan 2005 00:27:19 +0000
Subject: note 49142 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-83531@lists.php.net to get a copy of this message
Autoloading can be abused to simulate C++-style templates: <?php function __autoload($className) { $names = explode('__', $className, 2); if(count($names) != 2) return; eval( "class $className extends {$names[0]} { public static function getTemplateValue() { return {$names[1]}; } }" ); } class Dummy {} echo Dummy__HelloWorld::getTemplateValue()."\n"; // HelloWorld $bye = new Dummy__ByeBye(); echo $bye->getTemplateValue()."\n"; // ByeBye ?> Also a great way to confuse anyone trying to read/maintain your code. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49142 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49142&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49142&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49142&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49142&report=yes&reason=useless+example Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49142&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49142&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83531) next »