Solved

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

Posted on 2014-09-26
6
842 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now