Skip to content

Property access on lazy proxy may invoke magic method despite real instance guards #21478

@arnaud-lb

Description

@arnaud-lb

Description

The following code:

<?php

class Foo {
    public $_;

    public function __get($name) {
        global $proxy;
        printf("__get(\$%s) on %s\n", $name, $this::class);
        return $proxy->{$name};
    }
}

class Bar extends Foo {}

$rc = new ReflectionClass(Bar::class);
$proxy = $rc->newLazyProxy(function () {
    echo "Init\n";
    return new Foo();
});

$real = $rc->initializeLazyObject($proxy);
$real->x;

?>

Resulted in this output:

Init
__get($x) on Foo
__get($x) on Bar

But I expected this output instead:

Init
__get($x) on Foo

See #21463 (review).

PHP Version

PHP 8.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions