Skip to content

Proxies for __set/__unset need special handling if the parent implementation return type is explicitly declared as void #778

@DCoderLT

Description

@DCoderLT

The PHP documentation says that __set and __unset should return void, that their return values are ignored, and suggests these signatures:

public __set(string $name, mixed $value): void
public __unset(string $name): void

But if I actually declare the return types in my __set and __unset, the generated proxy methods still try to return the result of the proxied call. This results in a Compile Error: A void function must not return a value:

// my class
public function __set(string $name, mixed $value): void { ... }
public function __unset(string $name): void { ... }
// generated proxy
    public function __set($name, $value) : void
    {
        $this->initializerecc30 && ($this->initializerecc30->__invoke($valueHolder2e9e4, $this, '__set', array('name' => $name, 'value' => $value), $this->initializerecc30) || 1) && $this->valueHolder2e9e4 = $valueHolder2e9e4;

        if (isset(self::$publicPropertiesda7b8[$name])) {
            return ($this->valueHolder2e9e4->$name = $value); // ← uh oh
        }

        return $this->valueHolder2e9e4->__set($name, $value); // ← uh oh
    }

    public function __unset($name) : void
    {
        $this->initializerecc30 && ($this->initializerecc30->__invoke($valueHolder2e9e4, $this, '__unset', array('name' => $name), $this->initializerecc30) || 1) && $this->valueHolder2e9e4 = $valueHolder2e9e4;

        if (isset(self::$publicPropertiesda7b8[$name])) {
            unset($this->valueHolder2e9e4->$name);

            return;
        }

        return $this->valueHolder2e9e4->__unset($name); // ← uh oh
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions