Bug #79053 [Com]: No error is reported when using null coalescing operator

From: Date: Wed, 01 Jan 2020 14:00:32 +0000
Subject: Bug #79053 [Com]: No error is reported when using null coalescing operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224652@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79053&edit=1 ID: 79053 Comment by: bugreports at gmail dot com Reported by: rubencm at gmail dot com Summary: No error is reported when using null coalescing operator Status: Open Type: Bug Package: *General Issues PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: 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; Previous Comments: ------------------------------------------------------------------------ [2020-01-01 13:57:50] bugreports at gmail dot com > But I thought that all this cases should have the same behavior they have but you compare different cases ------------------- Notice: Trying to access array offset on value of type bool in /mnt/data/downloads/test.php on line 4 line 4 don't use coalescing operator at all return false['']; ------------------- Notice: Trying to access array offset on value of type bool in /mnt/data/downloads/test.php on line 7 line 7 don't use coalescing operator at all false['']; ------------------- this is line 9 and don#t throw a warning bar()??false; Notice: Trying to access array offset on value of type bool in /mnt/data/downloads/test.php on line 4 would you mind which line trhows the error? it happens inside line 4 again which *does not use* null coalescing operator at all ------------------------------------------------------------------------ [2020-01-01 13:52:46] rubencm at gmail dot com 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; ------------------------------------------------------------------------ [2020-01-01 13:48:20] bugreports at gmail dot com <?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 ?> ------------------------------------------------------------------------ [2020-01-01 13:44:38] bugreports at gmail dot com 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 ------------------------------------------------------------------------ [2020-01-01 13:41:32] rubencm at gmail dot com Here is an equivalent codes with diferent behavior <?php function bar() { return false['']; } var_dump(bar()??false); ?> <?php var_dump(false['']??false); ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=79053 -- Edit this bug report at https://bugs.php.net/bug.php?id=79053&edit=1

« previous php.bugs (#224652) next »