PHP 5.4到5.3转换

Are their any good resources when you are trying to get a PHP script written in a newer version to work on an older version; Specifically 5.4 to 5.3?

I have even checked out articles about the changes and I cannot seem to figure out what I am doing wrong.


Here is the error I am getting, at this moment:

Parse error: syntax error, unexpected '[' in Schedule.php on line 113

And the code it is referring to:

private static $GAMES_QUERY = array('season' => null, 'gameType' => null);
.....
public function getSeason(){
$test = array_keys(self::$GAMES_QUERY)[0]; //<<<<<<<<<< line:113
return($this->query[$test]);
}

Everything I have seen seems to say that 5.3 had self::, array_keys, and the ability to access arrays like that.

try...

$test = array_keys(self::$GAMES_QUERY);
$test = $test[0];

If I'm not mistaken, you can't use the key reference [0] in the same declaration in 5.3 like you can in 5.4 and javascript, etc.

That syntax was actually added in 5.4: http://docs.php.net/manual/en/migration54.new-features.php

So, you'll need a temporary variable to hold the result of the function, then access the index you want.

In versions lower than PHP 5.4 for the case you have you can make use of the list keywordDocs:

list($test) = array_keys(self::$GAMES_QUERY);

That works in PHP 5.4, too. But it does deal better with NULL cases than the new in PHP 5.4 array dereferencingDocs.