Skip to content

Commit eb66c66

Browse files
authored
Merge pull request #505 from chrisbckr/php82-AllowDynamicProperties
* Added AllowDynamicPropertis on V8Js, V8Object and V8Function
2 parents 7c40690 + 83431fb commit eb66c66

7 files changed

+34
-3
lines changed

tests/has_property_after_dispose.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Test V8::executeString() : has_property after dispose
55
--FILE--
66
<?php
77

8+
#[AllowDynamicProperties]
89
class Foo {
910
function callMe($x) {
1011
var_dump(property_exists($x, 'bla'));

tests/issue_250_001.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Test V8::executeString() : Issue #250 (early free of array)
55
--FILE--
66
<?php
77

8+
#[AllowDynamicProperties]
89
class TestObject {
910

1011
private $data = [];
@@ -55,9 +56,9 @@ try {
5556
?>
5657
===EOF===
5758
--EXPECTF--
58-
Fatal error: Uncaught Error: Attempt to modify property "b" on null in %s%eissue_250_001.php:9
59+
Fatal error: Uncaught Error: Attempt to modify property "b" on null in %s%eissue_250_001.php:10
5960
Stack trace:
6061
#0 [internal function]: TestObject->setTitle('ouch')
61-
#1 %s%eissue_250_001.php(44): V8Js->executeString(' var v1 = se...')
62+
#1 %s%eissue_250_001.php(45): V8Js->executeString(' var v1 = se...')
6263
#2 {main}
63-
thrown in %s%eissue_250_001.php on line 9
64+
thrown in %s%eissue_250_001.php on line 10

tests/property_visibility-has-property.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - has property
55
--FILE--
66
<?php
77

8+
#[AllowDynamicProperties]
89
class Foo {
910
private $privBar = "privBar";
1011
protected $protBar = "protBar";

tests/property_visibility-set.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - set
55
--FILE--
66
<?php
77

8+
#[AllowDynamicProperties]
89
class Foo {
910
private $privBar = "privBar";
1011
protected $protBar = "protBar";

tests/use_after_dispose.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Test V8::executeString() : Use after dispose
55
--FILE--
66
<?php
77

8+
#[AllowDynamicProperties]
89
class Foo {
910
function callMe($x) {
1011
var_dump($x);

v8js_class.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern "C" {
3434
#include "zend_closures.h"
3535
#include "ext/spl/spl_exceptions.h"
3636
#include "zend_exceptions.h"
37+
#include "zend_attributes.h"
3738
}
3839

3940
#define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
@@ -1059,6 +1060,14 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
10591060
php_ce_v8js = zend_register_internal_class(&ce);
10601061
php_ce_v8js->create_object = v8js_new;
10611062

1063+
#if PHP_VERSION_ID >= 80200
1064+
php_ce_v8js->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
1065+
1066+
zend_string *attribute_name_AllowDynamicProperties_class_V8Js = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1);
1067+
zend_add_class_attribute(php_ce_v8js, attribute_name_AllowDynamicProperties_class_V8Js, 0);
1068+
zend_string_release(attribute_name_AllowDynamicProperties_class_V8Js);
1069+
#endif
1070+
10621071
/* V8Js handlers */
10631072
memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
10641073
v8js_object_handlers.clone_obj = NULL;

v8js_v8object_class.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C"
2929
#include "zend_closures.h"
3030
#include "ext/spl/spl_exceptions.h"
3131
#include "zend_exceptions.h"
32+
#include "zend_attributes.h"
3233
}
3334

3435
/* {{{ Class Entries */
@@ -899,11 +900,27 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
899900
php_ce_v8object->ce_flags |= ZEND_ACC_FINAL;
900901
php_ce_v8object->create_object = v8js_v8object_new;
901902

903+
#if PHP_VERSION_ID >= 80200
904+
php_ce_v8object->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
905+
906+
zend_string *attribute_name_AllowDynamicProperties_class_v8object = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1);
907+
zend_add_class_attribute(php_ce_v8object, attribute_name_AllowDynamicProperties_class_v8object, 0);
908+
zend_string_release(attribute_name_AllowDynamicProperties_class_v8object);
909+
#endif
910+
902911
/* V8Function Class */
903912
INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods);
904913
php_ce_v8function = zend_register_internal_class(&ce);
905914
php_ce_v8function->ce_flags |= ZEND_ACC_FINAL;
906915
php_ce_v8function->create_object = v8js_v8object_new;
916+
917+
#if PHP_VERSION_ID >= 80200
918+
php_ce_v8function->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
919+
920+
zend_string *attribute_name_AllowDynamicProperties_class_v8function = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1);
921+
zend_add_class_attribute(php_ce_v8function, attribute_name_AllowDynamicProperties_class_v8function, 0);
922+
zend_string_release(attribute_name_AllowDynamicProperties_class_v8function);
923+
#endif
907924

908925
/* V8Generator Class */
909926
INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);

0 commit comments

Comments
 (0)