Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy proxy calls magic methods twice #18038

Open
arnaud-lb opened this issue Mar 13, 2025 · 1 comment
Open

Lazy proxy calls magic methods twice #18038

arnaud-lb opened this issue Mar 13, 2025 · 1 comment

Comments

@arnaud-lb
Copy link
Member

Description

Access to properties of a lazy proxy are forwarded to the real instance. But if the access is made by a magic method, forwarding to the real instance may call the magic method again:

#[AllowDynamicProperties]
class C {
    public $_;
    public function __set($name, $value)
    {
        var_dump(__METHOD__);
        $this->$name = $value * 2;
    }
}

$rc = new ReflectionClass(C::class);

$obj = $rc->newLazyProxy(function () {
    echo "init\n";
    return new C;
});

$obj->prop = 1;
var_dump($obj->prop);

Resulted in this output:

string(8) "C::__set"
init
string(8) "C::__set"
int(4)

But I expected this output instead:

string(8) "C::__set"
init
int(2)

PHP Version

PHP 8.4

Operating System

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants