phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.84k stars 200 forks source link

Return V8Object is endless iterable #316

Closed HoffmannP closed 7 years ago

HoffmannP commented 7 years ago

The following script produces an endless steam of lines containing "test: test":

<?php

$jscript = new V8Js();
$jscript->executeString("values = {}");
$jscript->executeString("values['test'] = 'test'");
$values = $jscript->executeString("values");

foreach ($values as $key => $value) {
    echo "$key: $value\n";
}
stesie commented 7 years ago

Nice catch :-)

PHP allows V8Js to refresh the properties after every round of iteration ... and V8js rebuilds the table from scratch every time (primarily to reflect properties being removed meanwhile), yet this resets the iterator heads