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

Object-Parameter with null as default #337

Closed
digilist opened this issue Sep 28, 2016 · 2 comments
Closed

Object-Parameter with null as default #337

digilist opened this issue Sep 28, 2016 · 2 comments
Assignees

Comments

@digilist
Copy link

Consider the following code:

class Foo {
    public function doSomething(\stdClass $a = null, $b) {
    }
}

$factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory();
$proxy = $factory->createProxy(
    Foo::class,
    function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {
        $wrappedObject = new Foo(); // instantiation logic here
        $initializer = null; // turning off further lazy initialization
    }
);


$proxy->doSomething(null, 'hi');

Executing the code fails with the following message:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to ProxyManagerGeneratedProxy__PM__\Foo\Generated8c05591d466b1fbc8b27e31e8bbeac21::doSomething() must be an instance of stdClass, null given, called in [...]

The function in the proxy is generated with the following code:

public function doSomething(\stdClass $a, $b)
{
    $this->initializer57ebd2a2dfdcf678896500 && $this->initializer57ebd2a2dfdcf678896500->__invoke($this->valueHolder57ebd2a2dfd75078219296, $this, 'doSomething', array('a' => $a, 'b' => $b), $this->initializer57ebd2a2dfdcf678896500);

    return $this->valueHolder57ebd2a2dfd75078219296->doSomething($a, $b);
}

It looks like the parameter's default value (null) is skipped, if the parameter is not optional. This prevents me from passing null to the function instead of an object.

This happens with version 1 and 2.

@digilist
Copy link
Author

Sorry, I dug deeper into the problem and it is actually a problem within zend-code. I will open a bug report there.

@Ocramius
Copy link
Owner

Was moved to zendframework/zend-code#95

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