|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77476 Different behavior of empty as of 7.0.6
Submitted: 2019-01-17 07:47 UTC Modified: 2019-02-12 15:35 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: php at sandstrom dot im Assigned:
Status: Open Package: Documentation problem
PHP Version: >= 7.0.6 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php at sandstrom dot im
New email:
PHP Version: OS:


 [2019-01-17 07:47 UTC] php at sandstrom dot im
From manual page:

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

is not empty

and when running on PHP 7 the output will be

is empty

Test script:
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;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-17 13:29 UTC]
-Summary: empty should be in the list of changed functions +Summary: Different behavior of empty as of 7.0.6 -Status: Open +Status: Feedback -PHP Version: Irrelevant +PHP Version: >= 7.0.6 -Assigned To: +Assigned To: cmb
 [2019-01-17 13:29 UTC]
Using 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

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 13:48 UTC]
-Status: Feedback +Status: Open
 [2019-01-17 13:48 UTC]
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,

[1] <>
 [2019-01-17 13:57 UTC]
-Status: Assigned +Status: Open -Assigned To: cmb +Assigned To:
 [2019-02-12 15:35 UTC]
Should the changelog notice be on the empty function or in the migration guide?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 10:01:29 2024 UTC