By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

Friend classes

P: n/a
Now that PHP5 has proper scoping for class properties and methods, I've
been looking in vain for friend classes, or wondering if there's another
way to achieve this effect:

class A {

protected var $v1;

....

}

class AHelper {
....

function ....
{

....
$helper = new AHelper ( ... );

....
if ($helper->v1) ...

}

So A has a property which really is not supposed to be public, but
AHelper (which does not inherit from A) has a special relationship with
A and wants to be able to delve inside it.

Note that just providing a public accessor won't help: it's logically
the same as making the property public.

C++ manages this by having 'friend classes' - classes which are allowed
inside a class even though they are not derived from it.

I suppose I could write a public accessor method which takes its caller
as an argument and checks its type before it will go ahead and fetch the
value; but that's inelegant, heavy, and only takes effect at run time.

Has anybody got any better suggestions?

[I see somebody asked the same question two weeks ago on faqts, but did
not get an answer)

Colin
Oct 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Colin Fine said the following on 19/10/2005 00:19:
Now that PHP5 has proper scoping for class properties and methods, I've
been looking in vain for friend classes, or wondering if there's another
way to achieve this effect:


PHP OOP is *extremely* limited. I'm afraid you're going to have to live
with it... ;)
--
Oli
Oct 19 '05 #2

P: n/a
> PHP OOP is *extremely* limited. I'm afraid you're going to have to live
with it... ;)


Hey who are you calling limited >;)

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.