note 62795 deleted from language.oop5.basic by bjori
| From: | bjori@php.net | Date: | Wed, 26 Apr 2006 16:48:11 +0000 |
| Subject: | note 62795 deleted from language.oop5.basic by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109768@lists.php.net to get a copy of this message | ||
Note Submitter: jcaplan at bogus dot amazon dot com
----
Searching the php site for the string "variable classes" did not produce anything, but the
note below by mrich at runbox dot removethis dot com indicates that the concept, analogous to
"variable functions", "variable methods", and "variable variables", is
indeed supported by the new operator.
<?
class MyClass { /* ... */ }
$y = new 'MyClass'; // rejected
$x = 'MyClass';
$y = new $x; // ok
$y = new $x(); // ok
function NewObj( $className ) {
$argv = func_get_args();
return call_user_func_array(
array( new ReflectionClass( $className ), 'newInstance' ),
array_shift( $argv )
);
}
$y = NewObj( $x ); // ok
$y = NewObj( 'MyClass' ); // ok
?>