Treadstone
Treadstone

Reputation: 39

PHP Parse issue

I am trying to setup my PHP site in my hosting server which is made from Codeigniter 2.2.0. Everything is fine only $end_date = $end_date ?: $start_date; this line of code generate a parse error -saying Parse error:

syntax error, unexpected ':' .

My hosting server php version is 5.2. How can I avoid this error?

Upvotes: 0

Views: 53

Answers (3)

Ricardo Santos
Ricardo Santos

Reputation: 1

local and host PHP versions were differents.

This code solved in booth.

$end_date = (!empty($end_date)) ? $end_date : $start_date;

Upvotes: 0

marekful
marekful

Reputation: 15351

In PHP, shorthand ternary operator is only available since version 5.3.

Quote:

Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.

Upvotes: 2

Maverick
Maverick

Reputation: 945

Try this

$end_date = (!empty($end_date)) ? $end_date : $start_date;

Upvotes: 1

Related Questions