I have this kind of class and i would like to take variable outside(return i guess) so that i would be able to do stuff with it.
class MyClass{
private function MyPrivate(){
$rows = 'SomeVar';
echo $rows.' is echoed from inside';
//return $rows;
return $this->rows;
}
function Foo(){
$this->MyPrivate();
//$this->rows;
}
//return $rows;
//return $this->rows;
}
$myclass = new MyClass;
$myclass->Foo();
//$myclass->rows;
echo '<br />';
echo $rows.'is echoed from outside';
Echoing variable inside the private function inside the class works, but echoing variable outside does not. Commented out code is what I tried to use to achieve wanted result. I did not make this class so I do not want to mess with it and change anything in it, because I fear it may mess things up.
this is my out put:
SomeVar is echoed from inside
is echoed from outside
As you can see in the second instance there is no SomeVar(variable) present. I am surprised it’s working though.
I am reading up on documentation and tutorials on the web for the past two days but this needs to be solved soon, that is why I posted. Please help. Thanks.
When you use the
returnstatement, you should assign it to a variable. Also, you should have returned$rows, not$this->rows, since they’re actually different variables: