Skip to content

SmartObject breaks DI in PHP 7.4 #201

Closed
@rixafy

Description

@rixafy

Version: latest

Bug Description

When you want to use DI in classes that are using SmartObject, and you define type of variable, magic function __set and __get (when getting) is called and SmartObject throws an exception, because variable is not public, there is also exception in &__get method.

Steps To Reproduce

Define data types in properties and inject them in a constcutror. I'm not sure if it is PHP bug or a new behaviour, this is example PHP code, __set is called when $this->testOne is initialised.

new class(new class() {}, new class() {}) {
    private object $testOne;
    private $testTwo;
    
    public function __construct(
        object $testOne, 
        object $testTwo
    ) {
        $this->testOne = $testOne;
        $this->testTwo = $testTwo;
    }
    
    public function __set(string $name, $value)
    {
        echo $name . ': ' . get_class($value) . PHP_EOL;
    }
};

Possible Solution

I'm not sure if it's a PHP bug (tested on php7.4beta-4), or it should happend, I didn't find any resources why is it happening.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions