note 98954 rejected from language.namespaces.dynamic by danbrown
| From: | danbrown@php.net | Date: | Sat, 17 Jul 2010 19:13:47 +0000 |
| Subject: | note 98954 rejected from language.namespaces.dynamic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170943@lists.php.net to get a copy of this message | ||
Note Submitter: wbeaumo1 at gmail dot com
----
Example #2 fails around here:
<?php
include 'example1.php';
$a = 'classname';
$obj = new $a; // prints classname::__construct
?>
If you actually split this code into a separate file, example1.php, and include it via the first
file, PHP will not find the class 'classname', EVEN IF YOU ADD THE NAMESPACE DECLARATION
TO THE SECOND FILE. So the lesson, I guess, is: always use fully qualified names.
(Tested using 5.3.1 on Windows.)