Suppose I had the following class:
class MyClass {
public function Talk() {
$Say = "Something";
return $Say;
}
}
I then started an instance of the class:
$Inst = new MyClass();
How can I now call $Say outside MyClass hence, for example, echo it on the document? For example, having something like:
$Said = "He" . $Say
I strongly recommend you read through http://php.net/manual/en/language.oop5.php. It will teach you the fundamentals of OOP in PHP.
In your example,
$Sayis just another variable declared withinTalk()‘s scope. It is not a class property.To make it a class property:
That defeats the purpose of
Talk()however.The last line ought to be
$said = 'He '. $inst->Talk();