From:             
Operating system: Linux 2.6.32 Debian
PHP version:      5.3.10
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:execution of code is inconsistent

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 bug report at https://bugs.php.net/bug.php?id=61612&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61612&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61612&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61612&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61612&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61612&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61612&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61612&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61612&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61612&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61612&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61612&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61612&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61612&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61612&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61612&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61612&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61612&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61612&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61612&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61612&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61612&r=mysqlcfg

Reply via email to