Skip to content

Commit

Permalink
Merge pull request pdepend#350 from emirb/yield-from
Browse files Browse the repository at this point in the history
Add support for "yield from" for PHP >7
  • Loading branch information
Emir Beganović authored Dec 6, 2017
2 parents 4f432c1 + 73f1cb5 commit 680366a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class PHPTokenizerInternal implements Tokenizer
'false' => Tokens::T_FALSE,
'trait' => Tokens::T_TRAIT,
'yield' => Tokens::T_YIELD,
'yield from' => Tokens::T_YIELD,
'parent' => Tokens::T_PARENT,
'finally' => Tokens::T_FINALLY,
'callable' => Tokens::T_CALLABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ public function testClassMethodNamesInvoked()
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testYieldFrom()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* Tests that the parser throws an exception when it detects an invalid
* token in a method or property declaration.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
function gen() {
yield from from(); // keys 0-2
}
function from() {
yield 1; // key 0
yield 2; // key 1
yield 3; // key 2
}
// pass false as second parameter to get an array [0, 1, 2, 3, 4]
var_dump(iterator_to_array(gen()));

0 comments on commit 680366a

Please sign in to comment.