Skip to content

Commit 6b8e195

Browse files
committed
Add _ex() variants for zend_*_property_*() functions taking the name as a Zend string
Also fix type for bool version and add missing zend_string value for static properties.
1 parent ca19051 commit 6b8e195

File tree

3 files changed

+165
-14
lines changed

3 files changed

+165
-14
lines changed

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ PHP 8.3 INTERNALS UPGRADE NOTES
6767
- zend_set_user_opcode_handler
6868
- zend_ssa_inference
6969
* Removed unused macros PHP_FNV1_32A_INIT and PHP_FNV1A_64_INIT. See GH-11114.
70+
* New zend_update_property_TYPE_ex() and zend_update_static_property_TYPE_ex()
71+
functions have been added that take the property name as a zend_string*.
7072

7173
========================
7274
2. Build system changes

Zend/zend_API.c

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,6 +4667,30 @@ ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const cha
46674667
}
46684668
/* }}} */
46694669

4670+
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */
4671+
{
4672+
zend_string *property;
4673+
zend_class_entry *old_scope = EG(fake_scope);
4674+
4675+
EG(fake_scope) = scope;
4676+
4677+
property = zend_string_init(name, name_length, 0);
4678+
object->handlers->unset_property(object, property, 0);
4679+
zend_string_release_ex(property, 0);
4680+
4681+
EG(fake_scope) = old_scope;
4682+
}
4683+
/* }}} */
4684+
4685+
ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name)
4686+
{
4687+
zend_class_entry *old_scope = EG(fake_scope);
4688+
4689+
EG(fake_scope) = scope;
4690+
object->handlers->unset_property(object, name, 0);
4691+
EG(fake_scope) = old_scope;
4692+
}
4693+
46704694
ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value) /* {{{ */
46714695
{
46724696
zend_class_entry *old_scope = EG(fake_scope);
@@ -4703,29 +4727,30 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *ob
47034727
}
47044728
/* }}} */
47054729

4706-
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */
4730+
ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name)
47074731
{
4708-
zend_string *property;
4709-
zend_class_entry *old_scope = EG(fake_scope);
4732+
zval tmp;
47104733

4711-
EG(fake_scope) = scope;
4734+
ZVAL_NULL(&tmp);
4735+
zend_update_property_ex(scope, object, name, &tmp);
4736+
}
47124737

4713-
property = zend_string_init(name, name_length, 0);
4714-
object->handlers->unset_property(object, property, 0);
4715-
zend_string_release_ex(property, 0);
4738+
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value) /* {{{ */
4739+
{
4740+
zval tmp;
47164741

4717-
EG(fake_scope) = old_scope;
4742+
ZVAL_BOOL(&tmp, value);
4743+
zend_update_property(scope, object, name, name_length, &tmp);
47184744
}
47194745
/* }}} */
47204746

4721-
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */
4747+
ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value)
47224748
{
47234749
zval tmp;
47244750

47254751
ZVAL_BOOL(&tmp, value);
4726-
zend_update_property(scope, object, name, name_length, &tmp);
4752+
zend_update_property_ex(scope, object, name, &tmp);
47274753
}
4728-
/* }}} */
47294754

47304755
ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */
47314756
{
@@ -4736,6 +4761,14 @@ ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *ob
47364761
}
47374762
/* }}} */
47384763

4764+
ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value)
4765+
{
4766+
zval tmp;
4767+
4768+
ZVAL_LONG(&tmp, value);
4769+
zend_update_property_ex(scope, object, name, &tmp);
4770+
}
4771+
47394772
ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value) /* {{{ */
47404773
{
47414774
zval tmp;
@@ -4745,6 +4778,14 @@ ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *
47454778
}
47464779
/* }}} */
47474780

4781+
ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value)
4782+
{
4783+
zval tmp;
4784+
4785+
ZVAL_DOUBLE(&tmp, value);
4786+
zend_update_property_ex(scope, object, name, &tmp);
4787+
}
4788+
47484789
ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value) /* {{{ */
47494790
{
47504791
zval tmp;
@@ -4754,6 +4795,14 @@ ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *obj
47544795
}
47554796
/* }}} */
47564797

4798+
ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value)
4799+
{
4800+
zval tmp;
4801+
4802+
ZVAL_STR(&tmp, value);
4803+
zend_update_property_ex(scope, object, name, &tmp);
4804+
}
4805+
47574806
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value) /* {{{ */
47584807
{
47594808
zval tmp;
@@ -4764,6 +4813,15 @@ ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *
47644813
}
47654814
/* }}} */
47664815

4816+
ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value)
4817+
{
4818+
zval tmp;
4819+
4820+
ZVAL_STRING(&tmp, value);
4821+
Z_SET_REFCOUNT(tmp, 0);
4822+
zend_update_property_ex(scope, object, name, &tmp);
4823+
}
4824+
47674825
ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
47684826
{
47694827
zval tmp;
@@ -4774,6 +4832,15 @@ ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object
47744832
}
47754833
/* }}} */
47764834

4835+
ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len)
4836+
{
4837+
zval tmp;
4838+
4839+
ZVAL_STRINGL(&tmp, value, value_len);
4840+
Z_SET_REFCOUNT(tmp, 0);
4841+
zend_update_property_ex(scope, object, name, &tmp);
4842+
}
4843+
47774844
ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value) /* {{{ */
47784845
{
47794846
zval *property, tmp;
@@ -4828,7 +4895,15 @@ ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, c
48284895
}
48294896
/* }}} */
48304897

4831-
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
4898+
ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name)
4899+
{
4900+
zval tmp;
4901+
4902+
ZVAL_NULL(&tmp);
4903+
return zend_update_static_property_ex(scope, name, &tmp);
4904+
}
4905+
4906+
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value) /* {{{ */
48324907
{
48334908
zval tmp;
48344909

@@ -4837,6 +4912,14 @@ ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, c
48374912
}
48384913
/* }}} */
48394914

4915+
ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value)
4916+
{
4917+
zval tmp;
4918+
4919+
ZVAL_BOOL(&tmp, value);
4920+
return zend_update_static_property_ex(scope, name, &tmp);
4921+
}
4922+
48404923
ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
48414924
{
48424925
zval tmp;
@@ -4846,6 +4929,14 @@ ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, c
48464929
}
48474930
/* }}} */
48484931

4932+
ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value)
4933+
{
4934+
zval tmp;
4935+
4936+
ZVAL_LONG(&tmp, value);
4937+
return zend_update_static_property_ex(scope, name, &tmp);
4938+
}
4939+
48494940
ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value) /* {{{ */
48504941
{
48514942
zval tmp;
@@ -4855,6 +4946,30 @@ ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope,
48554946
}
48564947
/* }}} */
48574948

4949+
ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value)
4950+
{
4951+
zval tmp;
4952+
4953+
ZVAL_DOUBLE(&tmp, value);
4954+
return zend_update_static_property_ex(scope, name, &tmp);
4955+
}
4956+
4957+
ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value)
4958+
{
4959+
zval tmp;
4960+
4961+
ZVAL_STR(&tmp, value);
4962+
return zend_update_static_property(scope, name, name_length, &tmp);
4963+
}
4964+
4965+
ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value)
4966+
{
4967+
zval tmp;
4968+
4969+
ZVAL_STR(&tmp, value);
4970+
return zend_update_static_property_ex(scope, name, &tmp);
4971+
}
4972+
48584973
ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value) /* {{{ */
48594974
{
48604975
zval tmp;
@@ -4865,6 +4980,15 @@ ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope,
48654980
}
48664981
/* }}} */
48674982

4983+
ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value)
4984+
{
4985+
zval tmp;
4986+
4987+
ZVAL_STRING(&tmp, value);
4988+
Z_SET_REFCOUNT(tmp, 0);
4989+
return zend_update_static_property_ex(scope, name, &tmp);
4990+
}
4991+
48684992
ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
48694993
{
48704994
zval tmp;
@@ -4875,6 +4999,15 @@ ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope
48754999
}
48765000
/* }}} */
48775001

5002+
ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len)
5003+
{
5004+
zval tmp;
5005+
5006+
ZVAL_STRINGL(&tmp, value, value_len);
5007+
Z_SET_REFCOUNT(tmp, 0);
5008+
return zend_update_static_property_ex(scope, name, &tmp);
5009+
}
5010+
48785011
ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv) /* {{{ */
48795012
{
48805013
zval *value;

Zend/zend_API.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,38 @@ static zend_always_inline HashTable *zend_class_backed_enum_table(zend_class_ent
490490
ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value);
491491
ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
492492
ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
493-
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
493+
ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name);
494+
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value);
495+
ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value);
494496
ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
497+
ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value);
495498
ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value);
499+
ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value);
496500
ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value);
501+
ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value);
497502
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
503+
ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value);
498504
ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length);
505+
ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len);
499506
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
507+
ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name);
500508

501509
ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
502510
ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
503511
ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
504-
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
512+
ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name);
513+
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value);
514+
ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value);
505515
ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
516+
ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value);
506517
ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
518+
ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value);
519+
ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value);
520+
ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value);
507521
ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
522+
ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value);
508523
ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
524+
ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len);
509525

510526
ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv);
511527
ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv);

0 commit comments

Comments
 (0)