#22749 [Opn]: Classes outside of namespaces cannot be called.

From: Date: Thu, 27 Mar 2003 23:58:25 +0000
Subject: #22749 [Opn]: Classes outside of namespaces cannot be called.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-36626@lists.php.net to get a copy of this message
ID: 22749 Updated by: mfischer@php.net Reported By: eric at evilwalrus dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: Windows XP PHP Version: 5CVS-2003-03-17 (dev) New Comment: Also pretty annoying if you want to declare a class extending the main exception class in your namespace. It simply doesn't work because its not "seen": $ php -r 'class myexception extends exception { } ' [no error, works] $ php -r 'namespace myscope { class myexception extends exception { } }' Command line code(1) : Fatal error - Class 'exception' not found I couldn't find a way to reference the global namespace. Previous Comments: ------------------------------------------------------------------------ [2003-03-17 11:33:25] eric at evilwalrus dot com If I have the following script, the class that is defined before the namespace cannot be called from within a class in the namespace. <?php class TestClass2 { function __construct() { print "TestClass2\n"; } } namespace Test { function newClass () { $new = new TestClass(); $new->newClass(); } class TestClass { function __construct() { print "TestClass\n"; } function newClass () { $new = new TestClass2(); } } } Test::newClass(); //$new = new TestClass2(); ?> This example will show the error "Fatal error: Class 'testclass2' not found in c:\usr\test.php on line 26" I'm assuming that this is done by design... but I would think that PHP would look for the class outside of the namespace since it is defined before the namespace. If you use the commented out line $new = new TestClass2; instead of the Test::newClass(); then it works properly, and the TestClass2 construct is called. As I said, I think this is done by design and isn't a bug... but I thought I would submit it because I'm not for sure. Any explination though would be very helpful to me. Thanks. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22749&edit=1

« previous php.bugs (#36626) next »