Edit report at https://bugs.php.net/bug.php?id=34341&edit=1

 ID:                 34341
 Updated by:         yohg...@php.net
 Reported by:        herve dot pages at laposte dot net
 Summary:            No warning for $a['zz'] if $a is not an assoc array
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Fedorac Core 3
 PHP Version:        4.4.0
 Block user comment: N
 Private report:     N

 New Comment:

String offset access is defined now, but
PHP does not raise errors for scalar types. (e.g. integer, bool)

Raising errors for this kind of access will break many codes. It's unlikely 
this 
behavior will be changed.


Previous Comments:
------------------------------------------------------------------------
[2005-09-02 03:44:54] herve dot pages at laposte dot net

Description:
------------
PHP doesn't output any warning for $a['zz'] if $a is not an assoc array.
This problem has been reported in Bug #33879 in the particular case where $a is 
a string. Since individual chars in a string can be accessed using the $a[] 
syntax, and since the key 'zz' will be automatically cast to 0, then I can 
understand why PHP will accept $a['zz'] without complaining.
But when $a is an integer, or a bool, or anything else that has nothing to do 
with an array (or a string), I don't see any reason why PHP should accept 
$a['zz'] without complaining! It would make some bugs much easier to find...

Reproduce code:
---------------
<?php
error_reporting(E_ALL);

$assoc = array();
$test = $assoc['zz']; // Warning "Undefined index: zz..." issued. OK

// Now what if the $assoc variable is replaced by a variable that is not
// an assoc array?
// The expected/natural behaviour would be that PHP complains even
// stronger because if such situation were occuring with a compiled
// language, any descent compiler would not even compile.

$not_an_assoc = 85;
$test = $not_an_assoc['zz']; // No warning issued!
echo gettype($test); // -> Display NULL

$not_an_assoc = "85";
$test = $not_an_assoc['zz']; // No warning issued!
echo $test; // -> Display 8
?>

Expected result:
----------------
It would be nice if PHP could tell me I'm doing something wrong with a warning 
or an error (that's why I'm using error_reporting(E_ALL) after all).



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=34341&edit=1

Reply via email to