Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my piece of code that i am trying to work with.

PHP
<?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
Updated 30-Jan-13 8:47am
v2
Comments
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.

http://www.php.net/manual/en/function.empty.php

1 solution

I tried your code and the main problem was in the if part:
PHP
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:
PHP
<?php
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}' />";
?>
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900