note 98954 added to language.namespaces.dynamic
| From: | wbeaumo1 at gmail dot com | Date: | Sat, 17 Jul 2010 19:07:57 +0000 |
| Subject: | note 98954 added to language.namespaces.dynamic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170942@lists.php.net to get a copy of this message | ||
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.)
----
Server IP: 69.147.83.197
Probable Submitter: 75.82.201.0
----
Manual Page -- http://www.php.net/manual/en/language.namespaces.dynamic.php
Edit -- https://master.php.net/note/edit/98954
Del: integrated -- https://master.php.net/note/delete/98954/integrated
Del: useless -- https://master.php.net/note/delete/98954/useless
Del: bad code -- https://master.php.net/note/delete/98954/bad+code
Del: spam -- https://master.php.net/note/delete/98954/spam
Del: non-english -- https://master.php.net/note/delete/98954/non-english
Del: in docs -- https://master.php.net/note/delete/98954/in+docs
Del: other reasons-- https://master.php.net/note/delete/98954
Reject -- https://master.php.net/note/reject/98954
Search -- https://master.php.net/manage/user-notes.php