|
Posted by Colin Fine on 10/19/05 02: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:
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
Navigation:
[Reply to this message]
|