Click here to Skip to main content
12,406,687 members (59,439 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP wordpress
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
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

Rate this: bad
 
good
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:
<?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}' />";
?>
  Permalink  
v2

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.160730.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2016
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