Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Wrong magic methods sequence with ?? operator #12695

Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
@nicolas-grekas

Description

@nicolas-grekas
Issue body actions

Description

When ?? is used to check a property using magic methods, PHP unconditionnaly calls both __isset and __get even when __isset did actually set the property.

Reproducer: https://3v4l.org/cDlNW

This script:

#[AllowDynamicProperties]
class A
{
    public function __get($n)
    {
        echo __FUNCTION__, "\n";

        return $this->$n;
    }

    public function __isset($n)
    {
        echo __FUNCTION__, "\n";

        $this->$n = 123;

        return true;
    }
}

$a = new A;

echo $a->foo ?? 234;

echoes this:

__isset
__get
123

while it should echo this:

__isset
123

PHP Version

All since 7.0.6

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.