Edit report at https://bugs.php.net/bug.php?id=55155&edit=1

 ID:                 55155
 Updated by:         patrickalla...@php.net
 Reported by:        patrickalla...@php.net
 Summary:            Cannot use non-bracketed namespaces in interactive
                     shell on multiple lines
 Status:             Assigned
 Type:               Bug
 Package:            Compile Failure
 Operating System:   Linux
 PHP Version:        5.3.6
 Assigned To:        johannes
 Block user comment: N
 Private report:     N

 New Comment:

> 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 ...


Previous Comments:
------------------------------------------------------------------------
[2011-07-07 12:06:40] johan...@php.net

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.

------------------------------------------------------------------------
[2011-07-07 05:32:46] patrickalla...@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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55155&edit=1

Reply via email to