5

Is it necessary to return any value or does it improve the speed? Sometimes its needed to code functions that not necessary return a value, some just do a set of functions or echo something. Does returning a value improves 'something'?, something like return true or return false?

1
  • Thanks for the answers, I just asked cause if something is returned, PHP stop reading the function. But, anyway, the function already reached its end, so the question came up. Thanks, Commented Oct 5, 2011 at 4:37

3 Answers 3

7

PHP functions do not need to return anything, and I doubt it would negatively affect the performance if you didn't return anything. If anything, it would positively affect the performance.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you show how returning "anything" would affect the performance positively?
@user3253002: I think I meant that if anything, not returning anything might improve the performance. But honestly I don't think you would be able to measure a difference either way -- it is such a small detail that it would almost certainly be overwhelmed by anything else in your script.
6

but, if you omit the "return something;" command the implicit returned value will be NULL

1 Comment

Good info for adding the correct return type declarations
5

No, returning a value from a function does not improve the speed of your script.

You do not need to return values from functions -> it is completely optional.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.