From:             frase at cs dot wisc dot edu
Operating system: Ubuntu 8.04 Hardy
PHP version:      5.3.0alpha1
PHP Bug Type:     Feature/Change Request
Bug description:  namespace visibility

Description:
------------
When PHP first introduced visibility, it did not yet have namespaces, so
the only applicable visibility schemes were related to classes -- members
were either global (public), or local to the class (private), possibly
including parents and children (protected).

But with the addition of namespaces, there is now a need for a visibility
scope between public and protected.  Developers (like me) will use
namespaces to create packages -- collections of classes that are meant to
work closely with each other.  In this context, it would be very convenient
to be able to make members visible to other (unrelated-by-inheritance)
classes within the same package (namespace), but hidden from the world
outside the package.

Since the 'namespace' keyword is currently only allowed on the first line
of a file, and therefore could not occur inside a class, I suggest re-using
it for this purpose rather than introducing another reserved word.

Reproduce code:
---------------
<?php
namespace Test;
class A {
  namespace static $nsVar = 'Test::A::nsVar';
  static function test() {
    echo __CLASS__." can see ".A::$nsVar."\n";
  }
}
class B {
  static function test() {
    echo __CLASS__." can see ".A::$nsVar."\n";
  }
}
Test::A::test();
Test::B::test();


Expected result:
----------------
Test::A can see Test::A::nsVar
Test::B can see Test::A::nsVar


Actual result:
--------------
(syntax error on 'namespace', line 4)

-- 
Edit bug report at http://bugs.php.net/?id=45681&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45681&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45681&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45681&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45681&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=45681&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45681&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45681&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45681&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45681&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45681&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=45681&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=45681&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45681&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45681&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45681&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45681&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45681&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45681&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45681&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45681&r=mysqlcfg

Reply via email to