I have one function that ends with:
return $authors;
How can I access this value in another function within the same class?
I've tried (in the second function)
$this->authors;
But it doesn't seem to do anything.
I have one function that ends with:
return $authors;
How can I access this value in another function within the same class?
I've tried (in the second function)
$this->authors;
But it doesn't seem to do anything.
public function returnAuthor()
{
return $author;
}
public function anotherMethod()
{
return $this->returnAuthor();
}
You could follow a similar method as stated in the above example. or you could define a property for your class, have one function assign a value to it and have another function return the value
Like so
class Book
{
public $author;
function __construct()
{
$this->author = 'Sir Conan Doyle';
}
function anotherMethod()
{
return $this->author;
}
}
Hope this helps!