php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69909 Type hint of a function are not checked when it's a generator
Submitted: 2015-06-23 09:37 UTC Modified: 2018-01-10 19:09 UTC
Votes:2
Avg. Score:2.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lyrixx at lyrixx dot info Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.5.26 OS: linux
Private report: No CVE-ID: None
 [2015-06-23 09:37 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-23 12:01 UTC] 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
 [2018-01-10 19:09 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2018-01-10 19:09 UTC] nikic@php.net
Fixed in 7.1 The argument binding code is now executed before the generator is suspended.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 14:01:30 2024 UTC