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

Proxy generation discards callable type-hint #259

Closed
natelenart opened this issue Mar 7, 2013 · 7 comments
Closed

Proxy generation discards callable type-hint #259

natelenart opened this issue Mar 7, 2013 · 7 comments

Comments

@natelenart
Copy link

As far as I can tell, this is a limitation in PHP itself as there is no $param->isCallable() method defined on ReflectionParameter. I'm not sure if there is any way of detecting callables at the moment (short of string parsing/regex), but it would be nice if the docs had a warning about it too (maybe they do and I haven't seen them).

# Doctrine\Common\Proxy\ProxyGenerator::_generateMethods

// We need to pick the type hint class too
if (null !== $paramClass) {
    $parameterString .= '\\' . $paramClass->getName() . ' ';
} elseif ($param->isArray()) {
    $parameterString .= 'array ';
}

Since callable is neither a class, nor an array, the generator strips it out, which leads to an ErrorException because the type-hint is not compatible with its parent:

Runtime Notice: Declaration of Proxies__CG__\Acme\DemoBundle\Entity\Subclass::methodCall() should be compatible with Acme\DemoBundle\Entity\Superclass::methodCall(callable $conditions) in /var/www/lab/app/cache/dev/doctrine/orm/Proxies/__CG__AcmeDemoBundleEntitySubclass.php line 8

In the meantime, I can easily change my code to remove the type-hint and check is_callable myself in my method.

I hope this is the right place to post this as current stable has the proxy generation code in ORM, but it has been moved to Common in the master branch.

@Ocramius
Copy link
Member

Ocramius commented Mar 7, 2013

@natelenart this is the right place for such an issue.

Can you confirm that following is broken then?

class Entity 
{
    public $id;
    public function setFoo(callable $foo) {}
}

@natelenart
Copy link
Author

Confirmed with latest dev: https://gist.github.com/natelenart/5110547

@Ocramius
Copy link
Member

Ocramius commented Mar 7, 2013

I'm on it

Ocramius added a commit to Ocramius/common that referenced this issue Mar 7, 2013
Ocramius added a commit to Ocramius/common that referenced this issue Mar 7, 2013
guilhermeblanco added a commit that referenced this issue Mar 7, 2013
@stof stof closed this as completed Mar 8, 2013
@nick4fake
Copy link

There is still an issue.
schmittjoh/JMSAopBundle#24

It seems that this bug still present in latest version.

@Ocramius
Copy link
Member

@nick4fake in common? I solved this issue in zendframework/zend-code, but not in schmittjoh/cg-library.

@nick4fake
Copy link

@Ocramius sorry, that bundle uses own library for generating proxies? Then this is certainly not doctrine issue.

@Ocramius
Copy link
Member

@nick4fake I don't think that it uses doctrine/common, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants