Solved

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

Posted on 2014-09-26
6
893 Views
Last Modified: 2014-09-26
Hi Experts,

Why do I keep getting:
Fatal error: Can't use function return value in write context

...when I:
   if(isset($_POST["email"]) || !empty(trim($_POST["email"])))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }

Open in new window


Thank you.
0
Comment
Question by:APD_Toronto
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40346657
if(isset($_POST["email"]) && !empty(trim($_POST["email"])))
0
 

Author Comment

by:APD_Toronto
ID: 40346664
makes logical sense - thanks, but same error
0
 
LVL 58

Expert Comment

by:Gary
ID: 40346668
What is the whole function
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:APD_Toronto
ID: 40346673
nothing too complex... The error is at Li.40

<?php

    $submit = '';
    $err = 0;
   
    $strName = '';
    $strEmail = '';
    $strSelect = '';
    $strMessage = '';
   
    
    if(isset($_GET["submit"]))
    {
        $submit = $_GET["submit"];
    }
 
    if($submit == '')
    {
        displayForm();
    }
    else 
    {
        validate();
    }

function validate()
{    
   global $err;
   
   global $strName;
   global $strEmail;
   global $strSelect;
   global $strMessage;
   
   if(isset($_POST["name"]))
   {
       $strName = $_POST["name"];
   }
   
   if(isset($_POST["email"]) && !empty(trim($_POST["email"])))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }
   
   if(isset($_POST["selection"]))
   {
       $strSelect = $_POST["selection"];
   }
   else
   { 
       $err = 1;
   }
   
   if(isset($_POST["message"]) && !empty(trim($_POST["message"])))
   {
       $strMessage = $_POST["message"];
   }
   else 
   {
       $err = 1;
   }
   
   if($err = 1)
   {
       displayForm();       
   }
   else
   {
       sendEmail();
   }    
}

Open in new window

0
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 500 total points
ID: 40346674
Your code should be changed to something like this:
if(isset($_POST["email"]) && (trim($_POST["email"]) != false))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }

Open in new window

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.
See this link:
http://us3.php.net/manual/en/function.empty.php
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40346678
As a general rule, compound statements with multiple function calls in the same line of code are a path to confusion.  I believe this statement is causing the problem:

empty(trim($_POST["email"]))

Try something more like this:

$email = trim($_POST['email']);
if (empty($email)) /* DO SOMETHING */

Long ago, PHP allowed this sort of thing, but it's not allowed any more.  That's one of the risks of getting old bits of code from the internet - you don't really know if it works.  Maybe it used to work and doesn't any more.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question