ID:               40782
 User updated by:  tims at arizona dot edu
-Summary:          boolean argument type to function throws Catchable
                   fatal error.
 Reported By:      tims at arizona dot edu
-Status:           Bogus
+Status:           Closed
 Bug Type:         Scripting Engine problem
 Operating System: Debian Linux
 PHP Version:      5.2.1
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2007-03-12 08:49:40] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://devzone.zend.com/node/view/id/1518#Heading8

------------------------------------------------------------------------

[2007-03-12 06:15:53] judas dot iscariote at gmail dot com

I indeed think that booleans should be accepted, but this is not a bug,
but a feature request :) actually type hinting works for Objects and
arrays **only**.

There is a patch to allow this IIRC but has not been merged into,and
probably will only be included with PHP6.

------------------------------------------------------------------------

[2007-03-12 06:04:45] 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



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40782&edit=1

Reply via email to