#37814 [Com]: Php shoul have class friends

From: Date: Mon, 06 Aug 2007 22:29:50 +0000
Subject: #37814 [Com]: Php shoul have class friends
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-115814@lists.php.net to get a copy of this message
ID: 37814 Comment by: michael at chunkycow dot com dot au Reported By: henke dot andersson at comhem dot se Status: Open Bug Type: Feature/Change Request Operating System: Linux Redhat 9 PHP Version: 6CVS-2006-06-15 (CVS) New Comment: The whole C++ friends thing is a mess, use an interface between your super friendly classes and simply dont use it if the classes arent joined at the hip, this would even help to keep nice low coupling and aid re-use. Private inner classes have some merit but are not a cure for common sense. Previous Comments: ------------------------------------------------------------------------ [2006-06-15 10:33:27] henke dot andersson at comhem dot se Description: ------------ Php should have a friend structure for classes, like c++. That way some normaly private things can be used by selected other classes and functions. An alternative would be to do it like Java with inner classes, but personaly I think that while inner classes could be usefull in php, friend classes should also exist like in c++. Reproduce code: --------------- <?php //my suggestion for the syntax class A { static function callB(B $b) { $b->privatefunction(); } } class B { friend class A; friend function C; private function privatefunction() { echo 'privatefunction!'; } } function C(B $b) { $b->privatefunction(); } $b=new B(); A::callB($b); C($b); Expected result: ---------------- Class A and function C should be able to call B::privatefunction. Actual result: -------------- Since this functionality doesn't exist the code wont even compile. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37814&edit=1

« previous php.bugs (#115814) next »