Please consider the following code. I have no idea how the yield
keyword works. Can anybody describe why the $this
produce an error with yield
.
class Collection {
/**
* Dependency injection container.
*
* @var Container
*/
protected $_Container = null;
/**
* Constructor.
*
* @param Container $Container Dependency injection container
* used to build providers.
*/
public function __construct(Container $Container) {
$this->_Container = $Container;
}
// ...
/**
* Finds providers of the given url.
*
* @todo Use PHP generators to yield providers.
* @param string $url An url which may be extracted.
* @return array An array of Essence\Provider.
*/
public function providers($url) {
$filters = $this->_Container->get('filters');
foreach ($filters as $name => $filter) {
if ($this->_matches($filter, $url)) {
yield $this->_Container->get($name);
}
}
}
}
The yield $this->_Container->get($name);
shows parse error. which is "Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /home/test.xyz/modules/embedder/vendor/Essence/Provider/Collection.php on line 71"
It will also help if you can describe how I can write different way of the line yield $this->_Container->get($name);
.
Thanks in Advance.