Question

I've been using the SimpleImage class for image manipulation but it doesn't work on one particular site the version of PHP on the server is 5.1.6 - so six years old

Parse error: syntax error, unexpected ':' in…

the lines in question which cause the error being

$height = $height ?: $width; 
$quality = $quality ?: $this->quality;
$filename = $filename ?: $this->filename;

Is there a workaround for this?

Was it helpful?

Solution 2

Because you're missing an argument in your ternary operator, it should be this syntax:

$height = $height ? $height : $width;
$quality = $quality ? $quality : $this->quality;
$filename = $filename ? $filename : $this->filename;

There should be 2 variables following the ? symbol, separated by a : symbol. The first variable is what is set if the condition (before the ?) is true. The second variable is what is set if the condition is false.

EDIT:

The syntax ?: is only available since PHP version 5.3, make sure you're running php 5.3 or greater.

OTHER TIPS

The ternary operator shorthand $val1 ?: $val2 was introduced in PHP 5.3, and is identical to $val1 ? $val1 : $val2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top