Doc #77476 [Opn->Fbk]: Different behavior of empty as of 7.0.6
| From: | girgias@php.net | Date: | Thu, 17 Jan 2019 13:29:37 +0000 |
| Subject: | Doc #77476 [Opn->Fbk]: Different behavior of empty as of 7.0.6 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16338@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: empty should be in the list of changed functions
+Summary: Different behavior of empty as of 7.0.6
-Status: Open
+Status: Feedback
Type: Documentation Problem
Package: Documentation problem
-PHP Version: Irrelevant
+PHP Version: >= 7.0.6
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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)?
Previous Comments:
------------------------------------------------------------------------
[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