brashrebel / client-dash-extension-boilerplate

This is a great starting point for anyone making an extension for Client Dash.
2 stars 5 forks source link

Syntax Error #4

Closed fpcorso closed 9 years ago

fpcorso commented 9 years ago

I had a user leave my addon a one-star review claiming that the addon crashed her site. She said that it said Parse error: syntax error, unexpected '[' in /home3/geispc28/public_html/wp-content/plugins/client-dash-custom-footer-addon/includes/settings.php on line 143 I looked and it is untouched code from the boilerplate's settings. This is the equivalent line that the error points to in the boilerplate: https://github.com/brashrebel/client-dash-extension-boilerplate/blob/master/inc/settings.php#L167

I have my addon installed on serveral sites with Client Dash and haven't experienced this error and my addon has had 90 downloads and no one else has mentioned it. Do you have any ideas?

joelworsham commented 9 years ago

Yup. This is an issue with PHP versioning and me not realizing it when coding. That's shorthand syntax for creating a new array []. This was introduced in (PHP 5.4)[http://php.net/releases/5_4_0.php]. So her server is running a version of PHP below 5.4. Typically, I won't support anything pre 5.3, but I will support 5.3 itself.

I cleaned Client Dash core from any instances of this, but I guess I hadn't done the boilerplate.

Replace that line with: isset( $setting['atts'] ) ? $setting['atts'] : array(), and it will work.

Replace any other instances of creating a new array like [] with this array().

Note: This is not the same as pushing to an array like so $myarray[] = 'test'. That is totally fine and supported since PHP 4.

Sorry about this inconvenience!

I will say though that PHP 5.4 was released 3 years ago and most servers should be running that or higher (but alas, not all of them do)

joelworsham commented 9 years ago

I just looked through the boilerplate, and this is the only line it occurs. I'll push a change to this soon, but in the meantime, that's the only code you should have to replace in your extension(s).

fpcorso commented 9 years ago

I have a usage tracking built into my main plugin (Quiz Master Next) and based on the data gathered from that, almost 30% of WordPress installations are using out of date PHP versions. My data says almost 3% are still on 5.2.

I completely forgot that the shorthand syntax wasn't in until 5.4. I will change that in my addon and get an update out. Thanks!

joelworsham commented 9 years ago

Man, that's a lot. 5.3 is officially "dead", let alone 5.2!

fpcorso commented 9 years ago

php_versions This is a graph of my data from my plugin. Version 5.4 is the purple, 5.3 is orange, 5.2 is dark blue, 5.5 is light blue, and 5.6 is green. I haven't got around to coding labels and percentages yet. It is usually only seen by me :)

fpcorso commented 9 years ago

It was very surprising when I first started collecting the data.

joelworsham commented 9 years ago

Holy crap. No kidding. Well, this is why I support 5.3 and up! All of those poor souls stuck in 5.2... Probably on 1and1 (you didn't hear me say that!)