Missing return argument warning on intentional null return for class method

Why is this even a warning?

I want to return null if they passed an argument that can't have anything done with it. I can then check if the return of the method is null to do something specific if the submitted param is unusable (like ignore the call).

Yes this can be useful. I don't think it's bad practice. Also PHP docs say returning null is the default, and don't give any warning about doing that anyway.

https://www.php.net/manual/en/functions.returning-values.php

3 comments
Comment actions Permalink

Please share a full code snippet. An example with just return; from this php.net article is parsed correctly: https://www.php.net/manual/en/functions.returning-values.php#120352

0
Comment actions Permalink

Dmitry, your example is from a function, not a class method.

Notice that my screenshot includes the word "public" before the word "function", which would not work in your example; it only works in a class.

0

Please sign in to leave a comment.