ID: 34044
Comment by: php at lost dot co dot nz
Reported By: arendjr at gmail dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.0.4
New Comment:
This would also be really useful for me writing unit tests so that I
can run 'white box' testing on internal private methods another class
(like I used to do back in the 'good' old days of PHP4... ;-)
Something like this:
class Util
{
friend class UtilTest;
private static function foo() {...}
}
class UtilTest
{
if( Util::foo() != $expected )
...
}
Previous Comments:
------------------------------------------------------------------------
[2005-08-09 02:11:57] arendjr at gmail dot com
Description:
------------
It would be really nice if PHP5 would support "friend classes", like
C++ does. This way, classes can give access to their private members to
other classes.
Reproduce code:
---------------
class Foo
{
friend class Bar; // using C++ syntax
private static $a = 5;
}
class Bar
{
public static function printA()
{
echo Foo::$a;
}
}
Bar::printA();
Expected result:
----------------
the above example would then print: "5"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34044&edit=1