For your information, here is another work-around for this issue, that even works with PHP4 (in case you need to be compatible):
<?php
function foo($foo)
{
assert('is_string($foo); // Invalid argument type');
}
?>
This single-line of code should fix it for most people. It will throw an error whenever the expression evaluates to false (if $foo is not a string).
Most errors concerning scalar types are found during development or unit-testing. PHPUnit is fine with these and reports failed assertions as failed tests, also presenting the included message.
Note that assertions need to be turned on for this to work. See the manual page on assertions for more details.
Note that you may deactivate the checks on the target machine, so this comes without any performance penalty. So don't hesitate to make extensive use of this PHP-feature.
Note though: DON'T RELY ON ASSERTIONS FOR CHECKING USER INPUT!
In that case you may want to try this code:
is_string($foo) || trigger_error('String expected', E_USER_ERROR);
Or: simply throw an exception (as usual).