So I have a very simple class that has a method called getThumbUrl() but when I try calling this method on an instance I get
Notice: Undefined property: FlickrImage::$getThumbUrl
But it is clearly there. Here is the code of the function inside of the FlickrImage class:
public function getThumbUrl()
{
return "http://farm".$this->_farm.".static.flickr.com/".$this->_server."/".$this->_id."_".$this->_secret."_t.jpg";
}
And here is where it fails inside of a different testing file:
$flickrTester = new FlickrManager();
$photos = $flickrTester->getPhotoStreamImages(9, 1);
foreach($photos as $photo) {
echo "<img src='$photo->getThumbUrl()' />";
}
Add curly-braces around the
$photo->getThumbUrl()in your echo. Here’s whats going on. Without surrounding the method in curly-braces PHP will try to resolve$photo->getThumbUrland will treat the()as plain text. The error that you’re seeing then is PHP complaining that$photo->getThumbUrlhasn’t been declared, as indeed it hasn’t.