Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use function return value in write context? [duplicate]

Tags:

php

I have this code:

public function __construct($Directory = null)  {     if ($Directory === null) {         trigger_error("Directory Must Be Set!", E_USER_ERROR);     }     if (isset($Directory)) {         if (!empty(trim($Directory))) { //Error Line             echo "test";          }     } } 

(The echo is for my debugging purposes.)

I get returned with the fatal error:

Can't use function return value in write context

According to PHP storm this returns:

Variable Expected

But using the code directly from this question:

White spaces throwing off HTML form validation

This is the correct syntax, as i've used it in the past... But, in this situation this is throwing an error. Why is this?

like image 548
Sophie Mackeral Avatar asked Jun 17 '13 01:06

Sophie Mackeral


1 Answers

From the PHP docs on the empty function:

Note: 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.

So you will have to split that line into something like the following:

$trimDir = trim($Directory); if(!empty($trimDir)) 
like image 145
Ken Herbert Avatar answered Oct 20 '22 20:10

Ken Herbert