|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-01-01 13:27 UTC] rubencm at gmail dot com
Description: ------------ When I try to access to an array offset on a boolean, a notice (a warning in master) is thrown. <?php false['']; // php notice: "Trying to access array offset on value of type bool" ?> But when I use the null coalescing operator with it, that error isn't reported <?php false['']??false; // false, no error ?> I'm not sure, but I think it's not the expected behavior, since possible errors are hidden. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 20:00:02 2026 UTC |
Well, in this case the notice is being reported, that still don't have much sense for me. <?php function bar() { trigger_error("foo", E_USER_NOTICE); return null; } var_dump(bar()??false);Here is an equivalent codes with diferent behavior <?php function bar() { return false['']; } var_dump(bar()??false); ?> <?php var_dump(false['']??false); ?>you can't seriously compare that becaus ethe case is completly wrong trigger_error("foo", E_USER_NOTICE); has nothing to do with "null coalescing operator" at all, you call the function and the function does what it is supposed to do, throw a E_USER_NOTICE why do you think "null coalescing operator" is involved here at all? teh function returns NULL and "bar()??false" does what it is supposed to do<?php function bar() { return false['']; } ?> this has again *nothing* to do with "null coalescing operator" because you are not using it at all, that way you would usie it <?php function bar() { return false[''] ?? NULL; } that all looks like lack of understand php basics ?>Well, just close the report if you want. But I thought that all this cases should have the same behavior, while in the last line the error isn't being reported. If is the expected behavior just close this. <?php function bar() { return false['']; } bar(); false['']; bar()??false; false['']??false;this would be your last example using null coalescing operator again: lack of basic understanding how php works! <?php function bar() { return false[''] ?? NULL; } bar(); false[''] ?? NULL; bar()??false; false['']??false;