note 100684 added to reflectionclass.newinstanceargs

From: Date: Sat, 30 Oct 2010 22:17:43 +0000
Subject: note 100684 added to reflectionclass.newinstanceargs
Groups: php.notes 
Request: Send a blank email to php-notes+get-173610@lists.php.net to get a copy of this message
This is the way I dynamically instantiate objects in my lightweight IoC container <?php class SimpleContainer { // ... // Creates an instance of an object with the provided array of arguments protected function instantiate($name, $args=array()){ if(empty($args)) return new $name(); else { $ref = new ReflectionClass($name); return $ref->newInstanceArgs($args); } } // ... } ?> I explicitly do NOT handle the case where a user passes constructor arguments for a constructor-less class, as I this SHOULD fail. ---- Server IP: 216.235.13.26 Probable Submitter: 96.50.118.113 ---- Manual Page -- http://www.php.net/manual/en/reflectionclass.newinstanceargs.php Edit -- https://master.php.net/note/edit/100684 Del: integrated -- https://master.php.net/note/delete/100684/integrated Del: useless -- https://master.php.net/note/delete/100684/useless Del: bad code -- https://master.php.net/note/delete/100684/bad+code Del: spam -- https://master.php.net/note/delete/100684/spam Del: non-english -- https://master.php.net/note/delete/100684/non-english Del: in docs -- https://master.php.net/note/delete/100684/in+docs Del: other reasons-- https://master.php.net/note/delete/100684 Reject -- https://master.php.net/note/reject/100684 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173610) next »