Skip to content

Setter/getter property is not called in own class static method #18046

@uaoleg

Description

@uaoleg

Description

class Foo
{
    protected string $bar;
    
    public function __set( string $name, mixed $value ): void
    {
        echo "from setter, prop name '{$name}'\n<br>";
    }

    public function __get( string $name ): null
    {
        echo "from getter, prop name '{$name}'\n<br>";
      
      return null;
    }

    public static function doo(): void
    {
        $foo = new Foo;
        $foo->bar = 'foobar';
        echo $foo->bar;
    }
}

// The getter/setter will be called
$foo = new Foo;
$foo->bar = 'asd';
echo $foo->bar;

// The getter/setter not called
Foo::doo();

PHP Version

PHP 8.1

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