Don't allow dynamic properties on generators

Noticed this because we leak those properties in GC. This was
never intended to be allowed.
This commit is contained in:
Nikita Popov 2020-09-07 19:06:53 +02:00
parent 628db3f3b5
commit 174dadf6b4
2 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,19 @@
--TEST--
It's not possible to assign dynamic properties on a generator
--FILE--
<?php
function gen() {
yield;
}
$gen = gen();
try {
$gen->prop = 42;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot create dynamic property Generator::$prop

View File

@ -1159,7 +1159,7 @@ void zend_register_generator_ce(void) /* {{{ */
INIT_CLASS_ENTRY(ce, "Generator", class_Generator_methods);
zend_ce_generator = zend_register_internal_class(&ce);
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL;
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_ce_generator->create_object = zend_generator_create;
zend_ce_generator->serialize = zend_class_serialize_deny;
zend_ce_generator->unserialize = zend_class_unserialize_deny;