|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-12 06:04 UTC] tims at arizona dot edu
Description:
------------
I have found a minimal reproducible test case that consistently fails. I believe this should work as a typed parameter but php5 dies with the result below.
Reproduce code:
---------------
$b = true;
function f( boolean $a ) { return $a; }
f( $b );
Expected result:
----------------
The above code does not do much except return the boolean that was passed in. My larger block of code uses typed arguments to ensure the type of data being passed in. The bool type does not work and I can not find a suitable workaround.
Actual result:
--------------
Catchable fatal error: Argument 1 passed to f() must be an instance of boolean, boolean given, called in /home/bink/Projects/opticsnow/web_software/dev_space/a.php on line 5 and defined in /home/bink/Projects/opticsnow/web_software/dev_space/a.php on line 4
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 26 23:00:01 2025 UTC |
For anyone that google's the thread, and wants a work-around you might try something like: function f( $bool_arg ) { if( ! is_bool( $bool_arg ) ) throw new Exception("Argument is not boolean."); .. rest of function declaration .. } at least until php6.