Social Twitter Facebook. Legal Privacy Policy Terms. You might want to examine the return value of those functions in detail, but since both are specified to return boolean types there should be no doubt. Its sole porpuse lies in that checking. Passing anything else will result in an error. I think the request does something to the input that makes it definitely not NULL. Check the documentation. And use it instead of empty. It solves the issue of keeping zeros int, float or string as non-empty.
Don't use it. This seems more verbose, but it shows clearly what you're doing. For structural objects it often makes sense to have a shortcut getter, e. In this case, don't use empty. Use isset in place of it. This will also allow 0 as an integer. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 2 months ago. Active 10 months ago.
Viewed 59k times. Improve this question. Peter Mortensen Run Run Akira Yamamoto 4, 4 4 gold badges 40 40 silver badges 41 41 bronze badges. Michael Haren Michael Haren Since OP is asking for a 'simpler' version of an extremely simple operation, I'm going to say that 'better' is what's actually warranted.
I turned it into a function. Show 8 more comments. Jason Plank 2, 4 4 gold badges 30 30 silver badges 39 39 bronze badges. Noumenon Because that would impair readability without solving anything.
It is real easy to read your suggestion as "if there is a length" while it of course means the opposite. Will not help for string with spaces only, if someone cares for that — airboss.
If the variable is not set, this will produce a warning — Konstantin Pereiaslov. Show 3 more comments. Use PHP's empty function. The following things are considered to be empty "" an empty string 0 0 as an integer 0.
Adal Adal 5 5 silver badges 12 12 bronze badges. If " " is not an acceptable value for a specific function, then using trim would be a great idea.
This will return false for "0", numeric 0 or 0. Ben Blank Ben Blank Id say if you get an array where you expected a string it should be an error. If you expect an array then you should have a separate filtering function for that.
0コメント