Possible Duplicate:
PHP type-hinting to primitive values?
Say, I create a function called
retrieveCount($count){
return ++$count;
}
Just a simple example. How do I set the function to accept the type to be integers only?
in Java, or other languages, we have:
public int retrieveCount(int count){
return ++count;
}
Is there a way do to the same thing in PHP? I read on the documentation that for OOP, PHP has type hinting for complex structures, such as objects, arrays, interfaces, etc, but no for scalar types (int, string).
Is this really the case, and we cannot specify the type?
Thank you
There are no direct scalar type hint possibilities PHP. But you can emulate it by checking the type inside the function and trigger an appropriate error: