From:             [EMAIL PROTECTED]
Operating system: Windows2000
PHP version:      4.4.4
PHP Bug Type:     Scripting Engine problem
Bug description:  array_key_exists inconsistent behavior

Description:
------------
Array indexes can be resources - in this case they are casted to int
automatically without any warning (E_STRICT is turned off in PHP5).
Hovewer, array_key_exists() throws warning if resource is passed as a key
and fails to recognize the key. 

This leads to confusion and is illustrated below.

More logical behavior is to make conversion automatically and display
warning only in E_STRICT mode for PHP5.

Yes, the problem persists in PHP5 as well. 


Reproduce code:
---------------
<?php
$depth = array();

$parser = xml_parser_create();

$depth[$parser] = "xxx";

echo "\n -".array_key_exists((int)$parser, $depth);
echo "\n -".array_key_exists("" + $parser, $depth);
echo "\n -".array_key_exists("" . $parser, $depth);
echo "\n -".array_key_exists((int) $parser, $depth);
echo "\n".$depth[$parser];
echo "\n".$depth[(int)$parser];
echo "\n";

$z = "" + $parser;
var_dump($z);
$z = "" . $parser;
var_dump($z);
$z = (string) $parser;
var_dump($z);
$z = strval($parser);
var_dump($z);

exit();


Expected result:
----------------
Warning: array_key_exists(): The first argument should be either a string
or an integer in C:\php51\test00.php on line 8

 -
 -1
 -
 -1
xxx
int(4)
string(14) "Resource id #4"
string(14) "Resource id #4"
string(14) "Resource id #4"


Actual result:
--------------
 -1
 -1
 -
 -1
xxx
int(4)
string(14) "Resource id #4"
string(14) "Resource id #4"
string(14) "Resource id #4"


-- 
Edit bug report at http://bugs.php.net/?id=39764&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39764&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39764&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39764&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39764&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39764&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39764&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39764&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39764&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39764&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39764&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39764&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39764&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39764&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39764&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39764&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39764&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39764&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39764&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39764&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39764&r=mysqlcfg

Reply via email to