Click here to Skip to main content
13,004,397 members (71,987 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Below is my piece of code that i am trying to work with.

<?php if (empty(userphoto($curauth))){echo "<img src='http://localhost/wordpress/wp-content/uploads/2013/01/NoImage.png' /?>"} else { userphoto($curauth)}   ?>

I am checking if userphoto($curauth) is null, i am replacing it with a default image.

Everytime i do this, i get the below error.

"Fatal error: Can't use function return value in write context in..."

Can someome guide me what is the problem exactly?
Posted 30-Jan-13 8:36am
Updated 30-Jan-13 8:47am
DinoRondelly 30-Jan-13 15:06pm
Why not drop empty and just check to see if its null?

If(userphote($curauth) !== null)


Not sure what version of php you are using but i found this

Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I tried your code and the main problem was in the if part:
if (empty(userphoto($curauth)))...

First, your userphoto function SHOULD not print/echo value, but only return path to user image.
Second, you need to assign return value from userphoto($curauth) function call into variable!
Third, you are missing semicolons after echo and userphoto function calls.

Check my updated code:
function userphoto($_) {
  return null; // Your code goes here
$photo = userphoto($curauth);
if (empty($photo))
  $photo = 'http://localhost/wordpress/wp-content/uploads/2013/01/NoImage.png';
echo "<img src='{$photo}' />";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100