Passing data between classes in PHP

w0ahitzj0hn

New Member
A couple of questions: q1:IN OOP PHP, what is the best way for a child class to make use of a var set by the parent class, and to set a variable in the parent class.What I want to do is run a function in the child class, that uses one of the variables in the parent class.I have done it by setting the variable I want to access as public, and entering it into the child class as an argument when calling the function, but it would be better if I could simply get it within the child class's function.Then, to set the variable in the parent class with the result of that function, I have returned the value into a setter class of the parent function. Here it is all in action:\[code\]$parentClass->set_maxpages($childClass->setMaxPages($cparentClass->contents));\[/code\]Q2:When I instantiate the child class, it runs the paren'ts constructor. If the child class has a constructor of its own, does it override the parnt class constructor.
 
Back
Top