Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

MethodReflection::getPrototype() crashes when method has no return #154

Open
erickcomp opened this issue Apr 17, 2018 · 5 comments
Open

Comments

@erickcomp
Copy link

When I use this method to grab the protype of a method of my class, it crashes with this error:

"Call to a member function getTypes() on boolean"

It happens because I have a method without return. My opinion is: the return type should be "void" on prototype. Issue #84 adresses the support for void. I've modified the code to make it return void. I could create a pull request if you guys want me to do so.

It was like this:

             $return = $docBlock->getTag('return');
             $returnTypes = $return->getTypes();
             $returnType = count($returnTypes) > 1 ? implode('|', $returnTypes) : $returnTypes[0];

And I've changed to this:

            $return = $docBlock->getTag('return');

            if($return === false)
            {
                $returnType = 'void';
            }
            else
            {
                $returnTypes = $return->getTypes();
                $returnType = count($returnTypes) > 1 ? implode('|', $returnTypes) : $returnTypes[0];
            }

If you don't think it should be void, at least set $returnType variable to empty string or null.
I've read the CONTRIBUTING.md, but I'm still pretty new to contributing on github, so fell free to get this code and push it into repository.

Regards

@Ocramius
Copy link
Member

Hi @ericklima-comp!

Can you maybe write an example class and snippet of zend-code that reproduces the actual crash?

If you want to, we can guide you through the pull-request process, so you familiarize with the platform and can apply the changes with your own attribution as well, but we first need a unit test. See https://github.com/zendframework/zend-code/blob/323188dc74e2780a401b8014804ef7edcc0fd865/test/Reflection/MethodReflectionTest.php for examples.

@erickcomp
Copy link
Author

Hello. I'm kind a dinossaur when it comes to testing.
Anyway, I've attached a whole test case. If you need anything else, just let me know.
zend-code-bug-test-ericklima.comp_2018.04.17.zip

@Ocramius
Copy link
Member

Ocramius commented Apr 18, 2018

@ericklima-comp you uploaded the entire zip with the repo - can you maybe just add your test to https://gist.github.com/ for now? I can then show you how to open a pull request here.

@erickcomp
Copy link
Author

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at laminas/laminas-code#6.

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

No branches or pull requests

4 participants