|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37814 Php shoul have class friends
Submitted: 2006-06-15 10:33 UTC Modified: 2007-08-07 12:05 UTC
Avg. Score:4.1 ± 1.3
Reproduced:7 of 8 (87.5%)
Same Version:3 (42.9%)
Same OS:1 (14.3%)
From: henke dot andersson at comhem dot se Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-06-15 10:33 UTC] henke dot andersson at comhem dot se
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:
//my suggestion for the syntax
class A {
 static function callB(B $b) {

class B {
 friend class A;
 friend function C;

 private function privatefunction() {
  echo 'privatefunction!';

function C(B $b) {

$b=new 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-06 22:29 UTC] michael at chunkycow dot com dot au
The whole C++ friends thing is a mess, use an interface between your super friendly classes and simply don`t use it if the classes aren`t 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.
 [2007-08-07 12:05 UTC]
We decided against those complex features.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC