Cassandra Cassandra - 7 months ago 14
PHP Question

PHP causing server error 500

Does anyone have a clue what it is about this bit of php code that would cause an apache2 webserver with nginx to throw a server error 500?

function cycleColsDbl() {
static $cols = ['transparent;', '#efefef;'], $i = 0;
$selectCol = ($i++/2 % 2 == 0) ? 0 : 1;
return $cols['$selectCol'];
}


The server suexec.log spat out a rather nonsensical claim:

[2016-04-17 08:34:34]: uid: (10003/usr) gid: (1003/1003) cmd: cgi_wrapper


And error.log says nothing at all about this.

The 500 is thrown on page load so the function never actually gets called.

Ideas anyone?

Answer

This $cols['$selectCol']; will look for a key $selectCol, not 0 or 1. It would look for 0 or 1 if you didn't make it literal, i.e. remove the single quotes.

Also, static $cols = ['transparent;', '#efefef;'] is not correct syntax to create an array in PHP.

function cycleColsDbl() {
    static $cols = array('transparent;', '#efefef;'), $i = 0;
    $selectCol = ($i++/2 % 2 == 0) ? 0 : 1;
    return $cols[$selectCol];
}