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

 ID:                 64194
 Comment by:         kevin dot swinton at gmail dot com
 Reported by:        marius at kitara dot nl
 Summary:            Null variable doesn't give error when trying to use
                     as array
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 Operating System:   FreeBSD 9.1
 PHP Version:        5.4.11
 Block user comment: N
 Private report:     N

 New Comment:

Without diving into the internals at this point:

$data is initially declared as a variable of type NULL.

In the first echo statement, the attempt to reference an index of 'wok' in 
$data is effectively ignored: the variable is not an ARRAY to begin with.

$data is then cast into a variable of type ARRAY ("$data['test'] = 'test';")

In the second echo statement, $data is an array, with an index, which PHP can 
enumerate against and ultimately determine that index 'wok' is not present.

Hence the first echo results in a NULL output, whilst the second results in PHP 
issuing an E_NOTICE.

I'd submit this issue is not related to the PHP core.


Previous Comments:
------------------------------------------------------------------------
[2013-02-12 10:50:42] marius at kitara dot nl

Description:
------------
When you define a string as null value you won't get any undefined errors. As 
soon you define a value in that same string you will see undefined errors.

Test script:
---------------
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);

$data = null;
echo $data['wok']; // Remains silent
$data['test'] = 'test';
echo $data['wok']; // Gives an undefined error


Expected result:
----------------
Both echo lines should give an undefined error.



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



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

Reply via email to