Doc #77476 [Opn]: Different behavior of empty as of 7.0.6

From: Date: Tue, 12 Feb 2019 15:35:13 +0000
Subject: Doc #77476 [Opn]: Different behavior of empty as of 7.0.6
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16399@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77476&edit=1 ID: 77476 Updated by: girgias@php.net Reported by: php at sandstrom dot im Summary: Different behavior of empty as of 7.0.6 Status: Open Type: Documentation Problem Package: Documentation problem PHP Version: >= 7.0.6 Block user comment: N Private report: N New Comment: Should the changelog notice be on the empty function or in the migration guide? Previous Comments: ------------------------------------------------------------------------ [2019-01-17 13:48:10] cmb@php.net Indeed, this looks like a bug fix (maybe 71359?), which we usually don't document explicitly. Considering @nikic's related comment[1], we may want to add changelog notices in this case, though. [1] <https://bugs.php.net/bug.php?id=69659#1462287177> ------------------------------------------------------------------------ [2019-01-17 13:29:37] girgias@php.net Using 3v4l.org it seems that this behavior was present prior to PHP 5.1.0 (so from PHP 5.0.2 to 5.0.5) and only has this behavior again as of PHP 7.0.6 c.f. https://3v4l.org/c2Xqr So I don't think this should go into the changed functions as it wasn't changed in the initial release of PHP 7.0 per se However, it's true that this odd behavior may need to be documented. Any idea Christoph what to do (or whom to refer this)? ------------------------------------------------------------------------ [2019-01-17 07:47:55] php at sandstrom dot im Description: ------------ --- From manual page: https://php.net/migration70.changed-functions --- Usage of the empty function in combination with magic methods that in PHP 5.6 returns false will return true in PHP 7. The cause is most likely the introduction of the null coalescing operator which causes the empty function to bail early. When running the test script on PHP 5.6 it will output Foo::__get(foo) Foo::__isset(bar) Foo::__get(bar) is not empty and when running on PHP 7 the output will be Foo::__isset(foo) is empty Test script: --------------- <?php class Foo { public function __get($name) { echo __METHOD__ . "($name)" . PHP_EOL; switch ($name) { case 'foo': return new Foo(); case 'bar': return 'bar'; default: return null; } } public function __isset($name) { echo __METHOD__ . "($name)" . PHP_EOL; return $name === 'bar'; } } $foo = new Foo(); echo (empty($foo->foo->bar) ? 'is empty' : 'is not empty') . PHP_EOL; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77476&edit=1

« previous php.doc.bugs (#16399) next »