Strange string -> array behaviour
Posted: Fri Oct 08, 2010 6:12 am
Hi
I'm using PHP 5.3.3 on Mac OS X. Today I had some strange behaviour with a string that I didn't expect. Now I'm curious if this is the expected behaviour, and if yes, why.
I'm using the following code:
The output of this code is
[syntax]
boolean true
boolean false
string 'test' (length=4)
boolean true
t
string 'test' (length=4)
test
[/syntax]
First I expected, that isset($input['value'] is wrong, because it's a string. Second I'm suprised, that what ever I insert for 'value' I received the first character of the string and no error. Why is this the case?
I'm using PHP 5.3.3 on Mac OS X. Today I had some strange behaviour with a string that I didn't expect. Now I'm curious if this is the expected behaviour, and if yes, why.
I'm using the following code:
Code: Select all
<?php
$input = 'test';
var_dump(is_string($input));
var_dump(is_array($input));
var_dump($input);
var_dump(isset($input['value']));
echo $input['value'];
var_dump($input);
echo $input;
[syntax]
boolean true
boolean false
string 'test' (length=4)
boolean true
t
string 'test' (length=4)
test
[/syntax]
First I expected, that isset($input['value'] is wrong, because it's a string. Second I'm suprised, that what ever I insert for 'value' I received the first character of the string and no error. Why is this the case?