note 99638 deleted from keyword.class by sobak
| From: | sobak@php.net | Date: | Sat, 12 Nov 2016 09:36:39 +0000 |
| Subject: | note 99638 deleted from keyword.class by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207078@lists.php.net to get a copy of this message | ||
Note Submitter: boukeversteegh at gmail dot com
----
You can also instantiate objects using variables containing the name of the class:
<?php
$type = 'Foo';
$foo = new $type();
print_r( $foo );
/* Prints:
Foo Object
(
)
*/
?>
The following works as well:
<?php
$somefoo = new Foo();
$anotherfoo = new $somefoo();
# so you don't have to do:
$anotherfoo = new get_class( $somefoo)();
?>