|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-02-12 10:50 UTC] 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.
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
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.