0

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()' />";
}
5
  • Hate to break it to you, but your foreach is calling $photo->getFullUrl(), but the function/method you posted is getThumbUrl(). Typo? Commented Apr 16, 2010 at 18:21
  • Sorry! that function exists too though Commented Apr 16, 2010 at 18:22
  • Can you provide some more code? How you get the images etc. From what you posted it is difficult to help. Commented Apr 16, 2010 at 18:24
  • I added a little more. The testing code is in a different file. And the getPhotoStreamImages method returns an array of FlickrPhotos. I did a var_dump and they are def in the array Commented Apr 16, 2010 at 18:30
  • Looks like if i take the function call out of the <img> element then it works. Can you not call object method from inside strings? Commented Apr 16, 2010 at 18:37

2 Answers 2

4

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()}' />";
}
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.