#42520 [Ver->Bgs]: Type hinting: function still gets called if type mismatch occurs
| From: | vrana@php.net | Date: | Wed, 21 Nov 2007 17:10:00 +0000 |
| Subject: | #42520 [Ver->Bgs]: Type hinting: function still gets called if type mismatch occurs | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-250@lists.php.net to get a copy of this message | ||
ID: 42520
Updated by: vrana@php.net
Reported By: konstantin at boyandin dot com
-Status: Verified
+Status: Bogus
Bug Type: Documentation problem
Operating System: Windows XP
PHP Version: 5.2.4
New Comment:
Nothing to document.
Previous Comments:
------------------------------------------------------------------------
[2007-09-06 07:53:50] rquadling@php.net
The returning False for the set_error_handler function is documented at
http://www.php.net/manual/en/function.set-error-handler.php
and is
available since V5.2.0
------------------------------------------------------------------------
[2007-09-06 07:50:48] rquadling@php.net
The code is only executed if you are catching recoverable errors (errno
= 4096 = E_RECOVERABLE_ERROR).
This is documented as ...
"Catchable fatal error. It indicates that a probably dangerous error
occured, but did not leave the Engine in an unstable state. If the error
is not caught by a user defined handle (see also set_error_handler()),
the application aborts as it was an E_ERROR."
This is available since PHP V5.2.0
http://www.php.net/manual/en/ref.errorfunc.php#errorfunc.constants.errorlevels.e-recoverable-error
So, this IS documented.
If you return False from set_error_handler the code aborts at that
stage with the Catchable fatal error report.
------------------------------------------------------------------------
[2007-09-05 09:57:49] konstantin at boyandin dot com
I have revised the reproducible code in accordance with the advice
given. Now it demonstrates that the function is called in pure PHP 5.2.4
installation.
<?php
set_error_handler("report_error");
$a = new B();
test($a);
class A {
public function show() {
print('Class A used');
}
}
class B {
public function show() {
print('Class B used');
}
}
function test(A $obj) {
$obj->show();
}
function report_error($errno, $errstr) {
echo "PHP error $errstr<br />";
}
?>
------------------------------------------------------------------------
[2007-09-03 09:09:54] konstantin at boyandin dot com
I was using the Windows binary PHP 5.2.4 distribution.
Note: xdebug was installed when I found that behavior (no explicit
options for it set in php.ini). I will try the situation without xdebug
but with error handler set/unset.
------------------------------------------------------------------------
[2007-09-03 08:20:51] bjori@php.net
bjori@lindsay:~$ php
<?php
function err($errno, $errstr) {
echo $errstr, "\n";
}
set_error_handler("err");
function typeHint(array $foo) {
echo "I am inside the type hint with :", gettype($foo), "\n";
}
typeHint("string");
Argument 1 passed to typeHint() must be an array, string given, called
in /home/bjori/- on line 10 and defined
I am inside the type hint with :string
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/42520
--
Edit this bug report at http://bugs.php.net/?id=42520&edit=1