tags:

views:

66

answers:

2

Hello,

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()' />";
}

Any ideas? Thanks!

+2  A: 

From what you say, you are calling it like:

FlickrImage::$getFullUrl

Rather than:

FlickrImage::$getFullUrl()

So you are missing () at the end.

foreach($photos as $photo) {
    echo '<img src="' . $photo->getThumbUrl() . '" />';
}
Sarfraz
+4  A: 

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->getThumbUrl and will treat the () as plain text. The error that you're seeing then is PHP complaining that $photo->getThumbUrl hasn't been declared, as indeed it hasn't.

foreach($photos as $photo) {
    echo "<img src='{$photo->getThumbUrl()}' />";
}
thetaiko