PHP Error - Empty () Function

7

I have the following error:

Fatal error: Can't use method return value in write context in /home/username/public_html/Administrar/application/controllers/holerites.php on line 29

The following sequence of lines 29 follows:

if(empty($this->input->post('periodo'))) $periodo = date("m")+1; else $periodo = $this->input->post('periodo');
if(empty($this->input->post('dataInicial'))) $data_inicial = ""; else $data_inicial = $this->input->post('dataInicial');
if(empty($this->input->post('dataFinal'))) $data_final = ""; else $data_final = $this->input->post('dataFinal');

I have no idea why, on localhost it works but not on the server.

    
asked by anonymous 01.08.2015 / 04:23

3 answers

6

empty is not a function, it is part of the language (also called "constructor language ").

You can not call over a value or a function or method return, as it always expects a reference (variable).

This is expected behavior in earlier versions of php 5.5.

Example in various php versions

    
01.08.2015 / 04:41
5

With the suggestion of Rray, I did it this way:

$periodo        = $this->input->post('periodo');
$dataInicial    = $this->input->post('dataInicial');
$dataFinal      = $this->input->post('dataFinal');

if(empty($periodo)) $periodo = date("m"); else $periodo = $this->input->post('periodo');
if(empty($dataInicial)) $data_inicial = ""; else $data_inicial = $this->input->post('dataInicial');
if(empty($dataFinal)) $data_final = ""; else $data_final = $this->input->post('dataFinal');
    
01.08.2015 / 05:05
2

As said by @rray, this "language constructor", empty , does not work with phrases in versions prior to PHP 5.5.

My suggestion to leave the simple code would be this:

if (! ($periodo = $this->input->post('periodo'))) {

   $periodo = date("m");
}

echo $periodo;

Or else:

 $periodo = $this->input->post('periodo') ?: date('m');
    
01.08.2015 / 16:50