zend-code icon indicating copy to clipboard operation
zend-code copied to clipboard

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

Open erickcomp opened this issue 7 years ago • 5 comments

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

erickcomp avatar Apr 17 '18 11:04 erickcomp

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.

Ocramius avatar Apr 17 '18 11:04 Ocramius

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

erickcomp avatar Apr 17 '18 21:04 erickcomp

@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.

Ocramius avatar Apr 18 '18 22:04 Ocramius

@Ocramius . Here it is! https://gist.github.com/ericklima-comp/bb32e0b9ec1a7ad9c430a201a96d5c3f

erickcomp avatar Apr 19 '18 13:04 erickcomp

This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at https://github.com/laminas/laminas-code/issues/6.

weierophinney avatar Dec 31 '19 21:12 weierophinney