|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-23 23:53 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 23:00:01 2025 UTC |
Description: ------------ I wrote CMS and have faced problem. The system is grounded on modular connection of classes. It is possible with __ autoload () - many thanks! But it would be healthy not to refresh value Magic constants inside __ autoload (). Namely __ FUNCTION __ and __ METHOD __. They lose meaning inside __ autoload () though could benefit. Advantage example I result in code. Reproduce code: --------------- // file: "index.php" // Example of desirable call function __autoload($Class){ require('engine/' . __CLASS__ . '/' . $Class . '.php'); } $Data = new _Data; $Data->RuleAdd("_NOT_NULL"); // file: "engine/_Data.php" class _Data{ $Rules; public function RuleAdd($RULE_NAME){ // add new callback function from class $RULE_NAME (directory "engine/_Data/_$RULE_NAME.php") $Rules[$RULE_NAME] = call_user_func(Array($RULE_NAME, 'main')); }} // file: "engine/_Data/_NOT_NULL.php" class _NOT_NULL{ public function main(&$DATA){ return ($DATA)?:true:false; }} Expected result: ---------------- In the given example at inquiry of an unknown class $RULE_NAME ("$this-> Rules [$RULE_NAME] = call_user_func (Array ($RULE_NAME, RULE_CALLBACK));") it is necessary to load automatically it from a folder "engine / _ Data / _ NON_NULL.php" under the class name and demanded $RULE_NAME, but function __ autoload () it does not allow. Complicating __ autoload () but this distortion is probably finite. Magic constants are illogically refreshed in __ autoload () because they are necessary when do not know where the code is now fulfilled. And when you write Magic constants in function __ autoload () you already known that they are equal. Therefore they there are useless. Actual result: -------------- __autoload($Class) load this file: "engine//NOT_NULL.php"