Knowledgebase

[php] accessing properties between classes

Posted by devonblzx, 01-10-2013, 04:01 PM
Say I have two classes, A and B, and I set a property (or variable) in class A. What are the different methods of accessing this property in class B? Example:

Posted by theglegroup, 01-11-2013, 02:09 AM
I apologize, but I'm not an expert Developer, so I'm not quite sure what you're referring to or what example you're trying to get me to see. Can you elaborate, please? Thanks.

Posted by Wildex999, 01-11-2013, 10:12 AM
Well, in your example here, $a is outside of the scope of class b(Class b does not know what $a is) So the most straight forward way of accomplishing what your example is trying is to simply pass on an instance of class a(reference) as an argument into the function message() like so: There are of course other ways, you can set a reference to class a as a variable in class b too. Been a while since I programmed php, so there are probably more ways that I don't remember right now. Hope that at least helps some =) Last edited by Wildex999; 01-11-2013 at 10:16 AM.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read


Language:

Client Login

Email

Password

Remember Me

Search