Skip to content

Commit 3151117

Browse files
committed
Ensure to initialize lazy object in foreach
foreach() by-passes the get_properties() handler and did not always trigger initialization.
1 parent 52fec69 commit 3151117

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

Zend/zend_vm_def.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,6 +6821,14 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR)
68216821
} else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
68226822
zend_object *zobj = Z_OBJ_P(array_ptr);
68236823
if (!zobj->ce->get_iterator) {
6824+
if (UNEXPECTED(zend_object_is_lazy(zobj))) {
6825+
zobj = zend_lazy_object_init(zobj);
6826+
if (UNEXPECTED(EG(exception))) {
6827+
UNDEF_RESULT();
6828+
FREE_OP1_IF_VAR();
6829+
HANDLE_EXCEPTION();
6830+
}
6831+
}
68246832
HashTable *properties = zobj->properties;
68256833
if (properties) {
68266834
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
@@ -6909,7 +6917,16 @@ ZEND_VM_COLD_CONST_HANDLER(125, ZEND_FE_RESET_RW, CONST|TMP|VAR|CV, JMP_ADDR)
69096917
ZEND_VM_NEXT_OPCODE();
69106918
} else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
69116919
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
6920+
zend_object *zobj = Z_OBJ_P(array_ptr);
69126921
HashTable *properties;
6922+
if (UNEXPECTED(zend_object_is_lazy(zobj))) {
6923+
zobj = zend_lazy_object_init(zobj);
6924+
if (UNEXPECTED(EG(exception))) {
6925+
UNDEF_RESULT();
6926+
FREE_OP1_IF_VAR();
6927+
HANDLE_EXCEPTION();
6928+
}
6929+
}
69136930
if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) {
69146931
if (array_ptr == array_ref) {
69156932
ZVAL_NEW_REF(array_ref, array_ref);

Zend/zend_vm_execute.h

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)