note 81393 deleted from language.oop5.autoload by felipe

From: Date: Mon, 24 Mar 2008 22:37:25 +0000
Subject: note 81393 deleted from language.oop5.autoload by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137500@lists.php.net to get a copy of this message
Note Submitter: cooper at mail dot tele dot dk ---- define( 'SYSTEMROOT', 'classes' ); /** * PHP 4 alternative class autoloading function, * params: useable with strings, integers, arrays and sub-arrays * * @param $classname The name of the class to instantiate * @param $params Array of parameters to pass to the class constructor. Primitive types only * @return object */ function &cl( $classname, $params = null ) { if( !class_exists( $classname )) { require_once( SYSTEMROOT . '/' . $classname . '.class.php' ); } if( $params != null ) { // build params for object $newParams = array(); foreach($params as $key=>$value) { $test = strtolower(substr($value,0,5)); if($test=='array') { eval( "\$myArray = array( ".substr($value, strpos($value, '(') + 1, strrpos($value, ')') - strpos($value, '(') - 1)." );" ); $newParams[$key] = $myArray; } else { $newParams[$key] = $value; } } // build string for object $count = 0; $strParams = ''; foreach($newParams as $keyParam => $valueParam) { $count++; $strParams .= "\$newParams[$keyParam]"; if($count < count($newParams)) { $strParams .= ","; } } // test object params eval( "\$object =& new $classname($strParams);" ); // return with params return $object; } return new $classname; } $foo =& cl('testclass', array( 'array( "abe"=>1, 2, hmm , "coool"=> 4,5,6=>array("niiice"=>"cooper","good!","great"))' , '222', 333, "im not used in object" ) ); echo "<pre>"; print_r($foo);

« previous php.notes (#137500) next »