Wednesday, 7 June 2017

php yield keyword in codeigniter

i am trying to use a generator function inside a codeigniter controller.



class Test extends CI_Controller {

public function __construct()
{
parent::__construct();

// Your own constructor code
}

public function testc()
{

$generator = $this->_gen_one_to_three();
foreach ($generator as $value) {
echo "$value\n";
}


}

function _gen_one_to_three()
{
for ($i = 1; $i <= 3; $i++)
{
yield $i;
}
}



}


But its gives me a



Parse error: syntax error, unexpected '$i' (T_VARIABLE) in /var/www/redsnail/application/controllers/test.php on line 30.



is there any difference while using the yield keyword inside a class ?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...