Re: [PHP] Odd behaviour of non-existent keys?

2004-08-26 Thread Geoff Caplan
Thanks for your help, everyone, especially Michael Sims.

I've reported the bug:

http://bugs.php.net/bug.php?id=29848

-- 
Geoff Caplan
Vario Software Ltd
(+44) 121-515 1154 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Odd behaviour of non-existent keys?

2004-08-26 Thread Michael Sims
Geoff Caplan wrote:
> Michael Sims wrote:
>> IMHO what you have described is a bug in PHP, and if I were you,
>> I'd report it as such.  If it's not a bug it at least has a very
>> high WTF factor.
>
> Problem with reporting is that I am using Debian Test and the current
> PHP version is too old to report. If someone with an current PHP
> version could replicate the problem, let me know and I will report it.
> Here is the code:
[snip]

I've replicated it in version 4.3.8, as well as five other previous versions
(I always keep my build directories around for a while on my development
server.)

Here's a suggestion so that you don't have to depend on other people to
reproduce it for you (and in case one of the PHP maintainers asks you to try
a snapshot):

Download the PHP tarball you want to test with (4.3.8 or snapshot or
whatever) and extract it in your home directory, then configure it and run
"make".  Then create your test script as a CLI script and make the shebang
line:

#!/home//php-/sapi/cli/php

This allows you to test with whatever version you wish without having to
actually install it.  FWIW...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Odd behaviour of non-existent keys?

2004-08-26 Thread Geoff Caplan
Hi folks,

Michael Sims wrote:

MS> IMHO what you have described is a bug in PHP, and if I were you,
MS> I'd report it as such.  If it's not a bug it at least has a very
MS> high WTF factor.

Problem with reporting is that I am using Debian Test and the current
PHP version is too old to report. If someone with an current PHP
version could replicate the problem, let me know and I will report it.
Here is the code:


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

print( 'Running tests for one non-existent key' ) ;

// Test isset() for non-existent key

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

// Use var_dump() to find out what is going on
// Expected: evaluate to NULL
// Actual: evaluated to 'string(1) "t"'
// ("x" is the first char of "test-value")

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

// Add another non-existent key and things
// work as expected

print( 'Running tests for two non-existent keys' ) ;

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

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





-- 
Geoff Caplan
Vario Software Ltd
(+44) 121-515 1154 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re [PHP] Odd behaviour of non-existent keys?

2004-08-25 Thread Geoff Caplan
Michael,

MS> IMHO what you have described is a bug in PHP, and if I were you, I'd report it as
MS> such.  If it's not a bug it at least has a very high WTF factor.

You are right - it does seem like a bug. But I assumed that something
as basic as this would have been spotted by now. I don't suppose it
would do any harm for me to report it, though, now there are at least
2 of us that think it looks odd.

-- 
Geoff Caplan
Vario Software Ltd
(+44) 121-515 1154 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Odd behaviour of non-existent keys?

2004-08-25 Thread John Holmes
From: "Geoff Caplan" <[EMAIL PROTECTED]>
Getting a result I don't understand.
Why does the non-existent key in the array below evaluate to the
first char of the array value?
$foo = '' ;
$foo['one']['two'] = 'test-value' ;
// Evaluates to: string(1) "t"
var_dump( $foo['one']['two']['three'] ) ;
// Evaluates to NULL, as expected
var_dump($foo['one']['two']['three']['four'] ) ;
Can anyone enlighten me?
Strings are arrays. PHP probably takes the string 'three' and converts it to 
a integer to see what "key" of the string you're requesting.

$foo = 'bar';
echo $foo[1]; //should echo 'a'
Does that help or do you need a deeper explanation (that I probably can't 
provide!) ;)

---John Holmes... 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php