|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-07-07 05:32 UTC] patrickallaert@php.net
Description:
------------
When using PHP in interactive mode (php -a) namespaces must be used with the
bracketed form:
php > namespace a {class A {}}
php > namespace b {class A {}}
or on the same line:
php > namespace a; class A {};
php > namespace b; class A {};
Using:
php > namespace a;
php > class A {};
php > namespace b;
php > class A {};
should be semantically exactly the same but results in:
PHP Fatal error: Cannot redeclare class A in php shell code on line 1
Test script:
---------------
$ php -a
php > namespace a;
php > class A {};
php > namespace b;
php > class A {};
Expected result:
----------------
No fatal error.
Actual result:
--------------
PHP Fatal error: Cannot redeclare class A in php shell code on line 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 06:00:02 2025 UTC |
Whenever you press enter and the shell assumes the code might be valid (crrect amount of quotes, braces etc.) it will be executed. So php > namespace a; and php > class A {}; will be executed independently, similar to being in different files being included. Maybe the logic for detecting whether it is executable code can be extended with this special case .. on second thought that's no good idea this would cause cases like this: php > namespace a; php > class A {} // declares a\A php > class A {} // declares A ... so we'd probably need a magic to set the current namespace. Not sure I really want that. Becomes quite a hack. Maybe it's best to document this limitation, but I'll try to think about a good thing to do.> php > namespace a; > php > class A {} // declares a\A > php > class A {} // declares A I would rather say that the second call to "class A{}" should remain as if we were still in the namespace "a". I would expect the following on the second declaration of class A: PHP Fatal error: Cannot redeclare class a\A in php shell code on ...