Inconsistent Behavior
| From: | Yasuo Ohgaki | Date: | Fri, 09 Aug 2002 06:16:30 +0000 |
| Subject: | Inconsistent Behavior | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-86677@lists.php.net to get a copy of this message | ||
<?php
$str = 'A';
$str[] = 'b';
?>
PHP Fatal error: [] operator not supported for strings in - on line 3
-(3) : Fatal error - [] operator not supported for strings
<?php
$int = 123;
$int[] = 'b';
var_dump($int);
?>
PHP Warning: Cannot use a scalar value as an array in - on line 3
-(3) : Warning - Cannot use a scalar value as an array
Warning: Cannot use a scalar value as an array in - on line 3
int(123)
We should raise fatal error for scalar, or raise warning
for string.
BTW, my preference is reinitialize var as array and assign
new element, raise notice error for this, though.
This would be a reasonable behavior for loosely typed
language to me.
--
Yasuo Ohgaki