Skip to content

Commit 3a5edcc

Browse files
committed
Fix create_object checks
Since PHP 8.3, object handlers may be changed by setting ce->default_object_handlers, rather than in ce->create_object. Some checks need to be extended to check for the default handlers. Closes phpGH-13272
1 parent 49f85c2 commit 3a5edcc

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

Diff for: Zend/Optimizer/escape_analysis.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,17 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
164164
/* These flags will always cause an exception */
165165
ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
166166
| ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT;
167-
if (ce && !ce->parent && !ce->create_object && !ce->constructor &&
168-
!ce->destructor && !ce->__get && !ce->__set &&
169-
!(ce->ce_flags & forbidden_flags) &&
170-
(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
167+
if (ce
168+
&& !ce->parent
169+
&& !ce->create_object
170+
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor
171+
&& ce->default_object_handlers->dtor_obj == zend_objects_destroy_object
172+
&& !ce->constructor
173+
&& !ce->destructor
174+
&& !ce->__get
175+
&& !ce->__set
176+
&& !(ce->ce_flags & forbidden_flags)
177+
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
171178
return 1;
172179
}
173180
break;
@@ -227,8 +234,15 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
227234
/* objects with destructors should escape */
228235
zend_class_entry *ce = zend_optimizer_get_class_entry_from_op1(
229236
script, op_array, opline);
230-
if (ce && !ce->create_object && !ce->constructor &&
231-
!ce->destructor && !ce->__get && !ce->__set && !ce->parent) {
237+
if (ce
238+
&& !ce->create_object
239+
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor
240+
&& ce->default_object_handlers->dtor_obj == zend_objects_destroy_object
241+
&& !ce->constructor
242+
&& !ce->destructor
243+
&& !ce->__get
244+
&& !ce->__set
245+
&& !ce->parent) {
232246
return 1;
233247
}
234248
break;

Diff for: Zend/Optimizer/zend_inference.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -3776,6 +3776,7 @@ static zend_always_inline zend_result _zend_update_type_info(
37763776
/* Unset properties will resort back to __get/__set */
37773777
if (ce
37783778
&& !ce->create_object
3779+
&& ce->default_object_handlers->read_property == zend_std_read_property
37793780
&& !ce->__get
37803781
&& !result_may_be_separated(ssa, ssa_op)) {
37813782
tmp &= ~MAY_BE_RC1;
@@ -5069,8 +5070,14 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
50695070
const zend_ssa_var_info *var_info = ssa->var_info + ssa_op->op1_use;
50705071
const zend_class_entry *ce = var_info->ce;
50715072

5072-
if (var_info->is_instanceof ||
5073-
!ce || ce->create_object || ce->__get || ce->__set || ce->parent) {
5073+
if (var_info->is_instanceof
5074+
|| !ce
5075+
|| ce->create_object
5076+
|| ce->default_object_handlers->write_property != zend_std_write_property
5077+
|| ce->default_object_handlers->get_property_ptr_ptr != zend_std_get_property_ptr_ptr
5078+
|| ce->__get
5079+
|| ce->__set
5080+
|| ce->parent) {
50745081
return 1;
50755082
}
50765083

0 commit comments

Comments
 (0)