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

 ID:               34044
 Comment by:       alsarg72 at gmail dot com
 Reported by:      arendjr at gmail dot com
 Summary:          Support for friend classes
 Status:           Wont fix
 Type:             Feature/Change Request
 Package:          Feature/Change Request
 Operating System: *
 PHP Version:      *

 New Comment:

Yeah. PHP's fundamental OO credentials are very poor in general

for many reasons that unfortunately are in ways that are not

fixable without completely replacing the language because of

really basic stuff like so much being in the global namespace,

it's reliance so heavily on global variables, etc, and

developers who work with PHP and have not come from a language

that does a decent job of OO can't really be expected to know

much different. I'm hoping to get back to C++ soon.


Previous Comments:
------------------------------------------------------------------------
[2010-05-04 07:40:25] neel dot basu dot z at gmail dot com

Ya friend functions would be a nice thing.

as PHP doesn't support many interesting keys of OOPS like Template,
friend etc.. 

(I know Java doesn't support most of them too, But thats not a good
excuse, cause 

in PHP some of this can be supported with minimum change in Code) Its
not 

possible to maintain Proper Coding Standard. and Programmers are forced
code in a 

bad way. designing patterns/idioms cannot be followed.

------------------------------------------------------------------------
[2006-10-11 19:01:09] he...@php.net

Long ago we decided against 'friend' declarations.

------------------------------------------------------------------------
[2006-10-11 12:22:24] goliath dot mailinglist at gmx dot de

I'm developing an OOP CMS, too. This feature is really elementary for
complex systems where you want to limit access to the internals.
Currently I developed a system to access protected methods from outside
(using one base-class, a list  to control the access and some secure
handshake when accessing the method), but thats detouring. Would be nice
to see some friend-system (like C++, or package -systemlike Java) in
PHP6.

If someone is interested in the code I mentioned above, I can post it.

------------------------------------------------------------------------
[2006-09-03 18:34:38] linus dot martensson at elplan-gm dot se

I'm developing an OOP CMS, and the lack of friend objects prevents me
from disallowing layouts access to unsafe internal variables. It's
actually a rather severe problem when you try writing an advanced
system.

------------------------------------------------------------------------
[2006-06-16 21:34:45] tsteiner at nerdclub dot net

In PHP 5.1, it is possible to simulate the function of friend classes
with __get and __set (I think PHP 5.0 triggers an error when trying to
access private properties even with __get or __set):



class HasFriends

{

    private $__friends = array('MyFriend', 'OtherFriend');



    public function __get($key)

    {

        $trace = debug_backtrace();

        if(isset($trace[1]['class']) && in_array($trace[1]['class'],
$this->__friends)) {

            return $this->$key;

        }



        // normal __get() code here



        trigger_error('Cannot access private property ' . __CLASS__ .
'::$' . $key, E_USER_ERROR);

    }



    public function __set($key, $value)

    {

        $trace = debug_backtrace();

        if(isset($trace[1]['class']) && in_array($trace[1]['class'],
$this->__friends)) {

            return $this->$key = $value;

        }



        // normal __set() code here



        trigger_error('Cannot access private property ' . __CLASS__ .
'::$' . $key, E_USER_ERROR);

    }

}

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=34044


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

Reply via email to