From:             geoff at variosoft dot com
Operating system: Linux
PHP version:      4.3.8
PHP Bug Type:     Arrays related
Bug description:  Non-existent keys evaluate to string

Description:
------------
In a multi-dimensional assoc array with a depth of x, an unset key at
depth x+1 evaluates unexpectedly to a string when using var_dump() - the
1st char of the array value. 

This means that isset() returns TRUE when testing for the unset key, which
makes it hard to test for non-existence.

An unset key with a depth of x+2 works as expected. 

This behaviour has been replicated in 4.3.8 and the 5 previous versions,
all on Linux.

Reproduce code:
---------------
$foo['one']['two'] = 'test-value' ;

if( isset( $foo['one']['two']['three'] ) )
{
    print( "Unexpected isset(): evaluated to TRUE<br>" ) ;
}
else
{
    print( "Expected isset(): evaluated to FALSE<br>" ) ;
}

print( 'var_dump() output (expecting NULL):<br>' ) ;
var_dump( $foo['one']['two']['three'] ) ;

Expected result:
----------------
As I am testing for an unset key, I expected isset() to return FALSE, and
var_dump() to return NULL.

Actual result:
--------------
In fact, isset() returns TRUE.

var_dump() gives a clue as to what is going on: it returns the first
character of the key's value string.

For unset keys of a depth of x + 2, isset() returns FALSE and var_dump()
returns NULL, as expected.

-- 
Edit bug report at http://bugs.php.net/?id=29848&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=29848&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29848&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29848&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=29848&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=29848&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=29848&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=29848&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=29848&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=29848&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=29848&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=29848&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=29848&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=29848&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=29848&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=29848&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=29848&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=29848&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=29848&r=float

Reply via email to