MyBB Community Forums

Full Version: Still Necessary To Check Input When Type Hinting?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
for example:

class Foo
	function this_method(array $this_array)
		//do I need this?
			// foreach or other code that would produce an error is $this_array is scalar

or is that just wasted code?
Yes, it's still required as a null value can be passed even when using type hinting IIRC.

Also remember that type hinting is a recent feature for PHP (5.4?).
Okay so if the user is on an older version of PHP will type hinting cause errors or just do nothing?
Just checked the docs, and you should be okay actually. I was getting a bit mixed up - arrays, interfaces and classes are okay since PHP 5.1 - it was the callable type hint that's new. It also seems that null cannot be passed unless specified as the default value so I was wrong on both counts. If you're type hinting, you shouldn't need to check the object type.
All right.

I suppose I could've checked all that myself. Where exactly are you looking? (I clicked around on forever and didn't see it)

Thanks so much Euan. Smile