Bug #61612 [Sus]: execution of code is inconsistent
| From: | jrsmeets at xs4all dot nl | Date: | Tue, 03 Apr 2012 21:43:43 +0000 |
| Subject: | Bug #61612 [Sus]: execution of code is inconsistent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169216@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61612&edit=1
ID: 61612
User updated by: jrsmeets at xs4all dot nl
Reported by: jrsmeets at xs4all dot nl
Summary: execution of code is inconsistent
Status: Suspended
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 2.6.32 Debian
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Dear Rasmus,
I expected that this would be difficult. I've searched this website and I also did some google
searches, and I found nothing like these bugs.
I'll try to install the application on another machine, which has Linux 2.4.31/Slackware 10.2.0
and PHP 5.2.11. Let's see what happens there.
As I said, I've already tried to create the bug in a small script and failed, but maybe in
slightly bigger test scripts these bugs will surface.
You can keep the ticket in suspended state for a while. And I'll try to report my findings
within a few weeks.
Previous Comments:
------------------------------------------------------------------------
[2012-04-03 19:53:34] rasmus@php.net
Sorry, without some sort of reproducable code snippet I don't see anything to go
on here. I can't recall any similar bug reports from anyone either.
------------------------------------------------------------------------
[2012-04-03 19:21:10] jrsmeets at xs4all dot nl
Description:
------------
I've been hit several times by what looks like a bug in the the scripting engine, or maybe an
over-active post-parsing optimizer.
What I see are error messages in my httpd log that make no sense when I inspect the program to check
the offending code.
Isolating the code in a small script does not replicate these problems: they only occur in the
environment of the application I'm working on.
Example:
# make sure that $n is a numeric scalar
if (!isset($n) || !is_numeric($n)) {
return $this;
}
# some code omitted, no changes to $n here
if (!isset($testvalue) || !is_array($testvalue) || !array_key_exists($n, $testvalue)) { return
$this; } # line 174
And PHP complains thusly in the error log:
array_key_exists(): The first argument should be either a string or an integer in [FILENAME.php] on
line 174
As you can see: the first argument of array_key_exists() in line 174 is certainly a scalar, so why
complain?
Another one:
$i = $first; # $first is an integer
# some code omitted, no changes to $i here
while ($i <= $last) {
# some code omitted, no changes to $i here
$displayName_utf8 = (is_array($displayNames) && array_key_exists($i, $displayNames)
&& isset($displayNames[$i])) ? bc_utf8($displayNames[$i]) : $i;
# some code omitted, no changes to $i here
$i ++;
}
produces this error message:
array_key_exists(): The first argument should be either a string or an integer in ...
Again this makes no sense: $i is an integer all the way.
I've also had problems with code like this
if (is_array($a) && is_scalar($k) && array_key_exists($k, $a)) {
And PHP complains that the second argument to array_key_exists() must be an array, or in other cases
that the first argument should be a string or int, which it is!
I've changed code like that to
if (isset($a[$k])) {
AFAIK, that is almost the same thing, except when $a is an object or $k is set, but not a scalar.
Last example:
$res = sendMailToUser(); # returns -1, 0 or 1
if ($res == -1) {
$errorMessage = 'Action not allowed';
}
else if ($res == 0) {
$errorMessage = 'Mail could not be sent';
}
else {
$errorMessage = 'Mail has been sent';
}
echo $res.'<br />';
echo $errorMessage.'<br />';
Expected result:
any of the three $res values with the corresponding $errorMessage
Actual result:
1
Action not allowed
Those two values do not belong together. [I'm not making this up.]
I've been able to work around most of these issue by changing the code a little bit. Like in
the last example, I wrote
$res = 0 + sendMailToUser();
and that solved the problem.
All of the other issues could also be solved by making this type of ridiculous changes to the code.
But that does not solve the underlying issue. And new issues might popup anywhere.
My setup: [from phpinfo()]
Apache/2.2.16 (Debian)
PHP Version 5.3.3-7+squeeze7 [ = 5.3.10]
Suhosin Patch 0.9.9.1, with Suhosin v0.9.32.1
Zend Engine v2.3.0
System Linux 2.6.32-5-686 #1 SMP Mon Jan 16 16:04:25 UTC 2012 i686
Build Date Feb 2 2012 18:20:23
Additional .ini files parsed /etc/php5/apache2/conf.d/gd.ini, /etc/php5/apache2/conf.d/imap.ini,
/etc/php5/apache2/conf.d/mcrypt.ini, /etc/php5/apache2/conf.d/mysql.ini,
/etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini,
/etc/php5/apache2/conf.d/pdo_mysql.ini, /etc/php5/apache2/conf.d/suhosin.ini
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,NTS
PHP Extension Build API20090626,NTS
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http,
ftp, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper,
string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61612&edit=1