March 5, 2012
parameter passing between two classes in two different files
Question by Aragorn
i want to ask how to pass parameter between two classes in two different files?
ex:
class a{
function aa(){
$var1 = 10;
return $var1;
}
}
//in different file
class b{
function bb(){
echo"$var1"; //how this can be achieved?
}
}
Answer by Starx
None of the answers here are right, since the op is asking to pass the parameter and not call it. The correct way to do it, is by creating an object of class b
class a{
function aa(){
$var = 10;
$obj_b = new b(); //create an object of the class b
$b -> bb($var); //pass the $var value to bb method of class b
}
}
//in different file
class b{
function bb($var){
echo $var; //now your values is passed here
}
}