Question

An invalid PHP string index usage that has been in place since 2008 today started causing an error. Debugging the reason for the invalid string index is not part of my question. The question is why does this only appear on certain servers?

Here is an example of the code:

$str = '0:828:555555';
$y = $str['id'];

The presence of the ['id'] appears to be the problem that causes the crash on one server but not on any of our production servers. So the invalid coding has been escaping for all these years.

The PHP levels and error_reporting levels unfortunately are not the same. The one that lets the error pass is 5.3.8. The one that has the error is 5.4.24. In addition, the 5.4.24 has E_STRICT but all the other settings are the same.

So I turned E_STRICT off and the error still happens.

The simplistic answer is "the PHP levels are not the same." But the error has in place for a long time, and so has the difference in PHP levels.

Any ideas on the cause of the server-dependent crash?

Was it helpful?

Solution

From the manual:

"As of PHP 5.4 string offsets have to either be integers or integer-like strings, otherwise a warning will be thrown. Previously an offset like "foo" was silently cast to 0."

http://www.php.net/manual/en/language.types.string.php

Probably PHP was recently updated to 5.4 on some of your servers, or you only recently noticed this error.

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