Skip to content

Commit 3187a21

Browse files
committed
Fix initialization of extra properties
1 parent 4e90052 commit 3187a21

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/tokenizer/tests/PhpToken_extension.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ FUNCTION FOO() {
1111
PHP;
1212

1313
class MyPhpToken extends PhpToken {
14+
public int $extra = 123;
15+
1416
public function getLoweredText(): string {
1517
return strtolower($this->text);
1618
}
1719
}
1820

1921
foreach (MyPhpToken::getAll($code) as $token) {
2022
echo $token->getLoweredText();
23+
24+
if ($token->extra !== 123) {
25+
echo "Missing property!\n";
26+
}
2127
}
2228

2329
?>

ext/tokenizer/tokenizer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ static void add_token(zval *return_value, int token_type,
307307
ZVAL_STR(OBJ_PROP_NUM(obj, 1), make_str(text, leng));
308308
ZVAL_LONG(OBJ_PROP_NUM(obj, 2), lineno);
309309
ZVAL_LONG(OBJ_PROP_NUM(obj, 3), text - LANG_SCNG(yy_start));
310+
311+
/* If the class is extended with additional properties, initialized them as well. */
312+
if (UNEXPECTED(token_class->default_properties_count > 4)) {
313+
zval *dst = OBJ_PROP_NUM(obj, 4);
314+
zval *src = &token_class->default_properties_table[4];
315+
zval *end = token_class->default_properties_table
316+
+ token_class->default_properties_count;
317+
for (; src < end; src++, dst++) {
318+
ZVAL_COPY_PROP(dst, src);
319+
}
320+
}
310321
} else if (token_type >= 256) {
311322
array_init(&token);
312323
add_next_index_long(&token, token_type);

0 commit comments

Comments
 (0)