note 92060 modified in language.oop5.autoload by danbrown

From: Date: Tue, 07 Jul 2009 15:33:52 +0000
Subject: note 92060 modified in language.oop5.autoload by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158018@lists.php.net to get a copy of this message
My idea for autoloading FUNCTIONS however only in a weird way : <?php function ex($parms) { $argvar = func_get_args(); $func = $argvar[0]; $funcargs = array_slice($argvar,1); if (function_exists($func)) { $returnvalue = call_user_func_array($func,$funcargs); } else { $funcpath = "scripts/".$func.".php"; require_once($funcpath); if (function_exists($func)) { $returnvalue = call_user_func_array($func,$funcargs); } else { die "SORRY $func IS NOT USABLE"; } } // return returned value :-) return $returnvalue; } ?> USAGE EXAMPLE: must be caled using the X function giving the real function as first parameter, like: $result = ex("add",1,2); // returns 3 if add function defined in add.php sums the first and second parameter.. --was-- My idea for autoloading FUNCTIONS however only in a weird way : function ex($parms) { $argvar = func_get_args(); $func = $argvar[0]; $funcargs = array_slice($argvar,1); if (function_exists($func)) { $returnvalue = call_user_func_array($func,$funcargs); } else { $funcpath = "scripts/".$func.".php"; require_once($funcpath); if (function_exists($func)) { $returnvalue = call_user_func_array($func,$funcargs); } else { die "SORRY $func IS NOT USABLE"; } } // return returned value :-) return $returnvalue; } USAGE EXAMPLE: must be caled using the X function giving the real function as first parameter, like: $result = ex("add",1,2); // returns 3 if add function defined in add.php sums the first and second parameter.. http://php.net/manual/en/language.oop5.autoload.php

« previous php.notes (#158018) next »