|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
40 + 46 = ?
Subscribe to this entry?

 [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: Thu Apr 18 18:01:28 2024 UTC