0

i have this codeline....

define('CSV_TEXTSIGN', '');

$var = ( empty( trim( CSV_TEXTSIGN ) ) ? '"' : CSV_TEXTSIGN );

this causes a error

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

but there are only valid functions...

bool empty ( mixed $var )
string trim ( string $str [, string $charlist ] )

i tried to switch " with ' in define and also use vars instead of constants

am i blind ? can someone explain me whats going wrong ?

Dwza
  • 6,494
  • 6
  • 41
  • 73
  • not really the same.. it's the same error but not really my problem... it's the trim combined with empty. the "duplicate" is handling from empty and sayes non about trim ^^ – Dwza Mar 24 '14 at 17:30
  • That answer was #1 on google when the error message was searched – mesutozer Mar 24 '14 at 17:35

3 Answers3

3

From the PHP documentation :

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 your code may look like :

$var = (!trim(CSV_TEXTSIGN) ? '"' : CSV_TEXTSIGN );

OR :

$trimed = trim(CSV_TEXTSIGN);
$var = empty($trimed) ? '"' : CSV_TEXTSIGN;
BMN
  • 8,253
  • 14
  • 48
  • 80
2

From http://php.net/empty

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.

Jez
  • 2,384
  • 1
  • 17
  • 31
  • omg... this is what you get when you sitting 8h infront of code... you will forgett to read the USEFUL comments and hints !! :D THX... – Dwza Mar 24 '14 at 17:26
1

Empty isn't actually a function - it's a language construct (similar to echo). Because of this, PHP parses it differently. Empty() only accepts a variable as an argument. Read more about language constructs here.

So, to answer your question, do something like this:

define('CSV_TEXTSIGN', '"');
$trimmedVal = trim( CSV_TEXTSIGN );

$var = ( empty( $trimmedVal ) ? '"' : CSV_TEXTSIGN );
seeARMS
  • 1,670
  • 1
  • 12
  • 14