473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Friend classes

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
2 2205
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
7
by: Jesper | last post by:
I need to grant a class access to protected fields of another class in the way its possible in C++ with the friend keyword. However I would like to keep the class protected towards other class...
4
by: darrel | last post by:
In the context of VB.net, when/why would one use a 'friend class'. I'm finding lots of references to friend classes on google, but not a simle definition of what they actually are. Actually, if...
2
by: anongroupaccount | last post by:
I have a smaller class that essentially acts as a record for a larger class (stored in a vector inside of the larger class). In a sense, it's splitting functionality over two classes. I don't...
8
by: toton | last post by:
Hi, I have a parser interface , which is class IParser{ public: void readHeader(Document& doc)= 0; void readCC(CC& cc) = 0; }; Now, there are 3 kinds of parser which extends (implements)...
3
by: Neal | last post by:
Hi all Why do I get a compiler error with the following code. Friend Class SomeClass End Class Public Class SomePublicClass Protected Friend Function AMethod As SomeClass
5
by: Amit Gupta | last post by:
How do I do it (either by friend or by any other hack). I have three class, I am just writing derivation below: class A{} class B{} class C : public class B{} class D: public class B ()
19
by: subramanian100in | last post by:
Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the section '1.8 Advice' has mentioned the following: Don't use global data(use members) Don't use global functions Don't use...
1
by: Immortal_Nephi | last post by:
I want to show you an example how two classes can have relationship instead of an inheritance. The inheritance is not an option if you want to define two classes. The relationship between two...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.