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

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

Open
weierophinney opened this issue Dec 31, 2019 · 4 comments
Open
Labels

Comments

@weierophinney
Copy link
Member

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


Originally posted by @ericklima-comp at zendframework/zend-code#154

@weierophinney
Copy link
Member Author

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.


Originally posted by @Ocramius at zendframework/zend-code#154 (comment)

@weierophinney
Copy link
Member 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


Originally posted by @ericklima-comp at zendframework/zend-code#154 (comment)

@weierophinney
Copy link
Member Author

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


Originally posted by @Ocramius at zendframework/zend-code#154 (comment)

@weierophinney
Copy link
Member Author

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

No branches or pull requests

1 participant