Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Yield from #42

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Yield from #42

wants to merge 13 commits into from

Conversation

thekid
Copy link
Contributor

@thekid thekid commented Sep 20, 2015

This pull request implements yield from as described in this PHP 7.0 RFC in both PHP and XP and makes it work in PHP >= 5.5

var values() {
  yield 1;
  yield 2;
}

var including() {
  yield 0;
  yield from self::values();
  yield 3;
}

// 0, 1, 2, 3
  • Yielding from a generator
  • Yielding from an iterator
  • Yielding from an array

@thekid
Copy link
Contributor Author

thekid commented Sep 20, 2015

Fails on HHVM: https://travis-ci.org/xp-lang/compiler/jobs/81253540:

HHVM

$recv= (yield $next);  // Fatal error: syntax error, unexpected T_YIELD
$recv= yield $next;    // Still doesn't work but at least parses!

PHP

$recv= (yield $next);  // Works as expectred
$recv= yield $next;    // Parse error (syntax error, unexpected '$next' (T_VARIABLE))

_Argl 😱_ - see also facebook/hhvm#1627

This is a terrible hack involving eval(), but the best I could find at
the moment. If we found a place for one-time initialization code, we
could include differing implementations there.
@thekid thekid added the php label Sep 20, 2015
@thekid thekid added the feature label Sep 20, 2015
@thekid
Copy link
Contributor Author

thekid commented Sep 20, 2015

Choosing emitter based on PHP runtime version has also been applied to master branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant