Bug #69909 [Opn->Csd]: Type hint of a function are not checked when it's a generator
| From: | nikic@php.net | Date: | Wed, 10 Jan 2018 19:09:42 +0000 |
| Subject: | Bug #69909 [Opn->Csd]: Type hint of a function are not checked when it's a generator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213461@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69909&edit=1
ID: 69909
Updated by: nikic@php.net
Reported by: lyrixx at lyrixx dot info
Summary: Type hint of a function are not checked when it's a
generator
-Status: Open
+Status: Closed
Type: Bug
Package: *General Issues
Operating System: linux
PHP Version: 5.5.26
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed in 7.1 The argument binding code is now executed before the generator is suspended.
Previous Comments:
------------------------------------------------------------------------
[2015-06-23 12:01:10] jpauli@php.net
This is because the call to the generator does not call the function actually, thus this latter
can't check its arguments.
However, triggering a method on the generator returns actually triggers the function call.
I attached a patch that fixes the issue by checking args in case of generator creation, however,
this will only work if you make use of the return value (which is not the case in your script)
Patch is at https://github.com/jpauli/php-src/tree/fix-69909
------------------------------------------------------------------------
[2015-06-23 09:37:29] lyrixx at lyrixx dot info
Description:
------------
If you don't "next" on the generator, the typehint of the function is not checked.
Test script:
---------------
<?php
function hello(closure $closure)
{
$closure('hello');
yield 10;
}
hello();
Expected result:
----------------
Argument 1 passed to hello must be an instance of Closure, none given
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69909&edit=1