Jump to content

Can't use function return value in write context? What?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Cyberen

Cyberen

    Newbie

  • Members
  • PipPip
  • 19 posts
I tried Googling the solution to this problem but come up empty, though it might be my fault as I am a newbie at PHP. I keep getting a "Can't use function return value in write context" error message when I add a conditional statement (3 lines from the bottom). The PHP code up to the line with an error is seen below. Any help would be greatly appreciated!

<?

ini_set('display_errors',1);

ini_set('error_reporting', E_ALL);

ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

error_reporting(E_ALL | E_STRICT);

ini_set('display_errors','Off'); 

include 'db.php';

if (!isset($_POST['action']))

{

//If not isset -> set with dumy value

$_POST['action'] = "undefine";

} 

session_start();

header("Cache-control: private");

//add to cart

if($_POST['action']=='add'){

  if(!isset($_SESSION['cart'])){

    $_SESSION['cart']=array(); 

  }

  $item=$_POST['id'] . '||';

  $item.=$_POST['glass'] . '||'; 

  $item.=$_POST['finishes'] . '||'; 

  $item.=$_POST['stocks'] . '||';

  $item.=$_POST['cord_colors'] . '||';

  $item.=$_POST['ceiling'] . '||';

  $item.=$_POST['glass_shape'] . '||';

  $item.=$_POST['leafs'] . '||';

  $item.=$_POST['ceil_cap'];

  array_push($_SESSION['cart'],$item);

  header("Location: viewcart2.php?back=" . urlencode("pro.php?id=" . $_POST['id']));

  exit;

}

?>


<?

/* Display categories */

$query = "SELECT id,category,description from categories where id!=11 and deleted=0 order by category";

$result = mysql_query($query) or die("Query failed : " . mysql_error());

$last=0;

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

  if($last>0){

    ?>

    <!-- | -->

    <?

    }

    ?>

    <!--<a href="cat.php?id=<?= $line['id'] ?>" class="sub"><?= $line['category']

    ?></a>-->


    <?

    if($_GET['id']==$line['id'] || $last==0){

      $description=stripslashes($line['description']);

      $title=stripslashes($line['category']);

      $last=$line['id'];

    }

  }

  if(isset($_GET['id'])){

 $last=$_GET['id'];

}


mysql_free_result($result);




//get product details and convert them into local variables

$query = "SELECT * from products where deleted=0 and id=" . $_GET['id'];

$result = mysql_query($query) or die("Query failed : " . mysql_error());

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

  $name = stripslashes($line['name']);

  $description = stripslashes($line['description']);

  $retail = stripslashes($line['retail']);

  $price = stripslashes($line['price']);

  $bulb = stripslashes($line['bulb']);

  $redirect = stripslashes($line['redirect']);

  $ceiling = stripslashes($line['ceiling']);

  $dims = stripslashes($line['dims']);

  $static = stripslashes($line['static']);

}

mysql_free_result($result);


$name = stripslashes($line['name']);

if (isset($name)&&((substr($name, 9,17)="Radiance")||(substr($name, 0,8)="Radiance")))

	{$viewcol=5;}

else {$viewcol=6;}

?>

Edited by Cyberen, 09 June 2011 - 11:29 AM.
forgot tags


#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas

Cyberen said:


if (isset($name)&&((substr($name, 9,17)="Radiance")||(substr($name, 0,8)="Radiance")))


You used the assignment operator (=) instead of the equivalence operator (==).
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Cyberen

Cyberen

    Newbie

  • Members
  • PipPip
  • 19 posts
D'oh! Thank you!:thumbup:

#4
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
I have suggested it earlier
http://forum.codecal...html#post301102

and is a standard coding practice advocated by many professional organizations that

place const on the left side of every comparison i.e.


if (isset($name)&&(("Radiance"==substr($name, 9,17))||("Radiance"==substr($name, 0,8))))

(

If you develop this as a habit and used = instead of ==, you would get a compile time error




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users