Skip to content

Commit 4d7fcea

Browse files
committed
Fix handling of undef property during foreach by ref on hooked class
1 parent f5d4781 commit 4d7fcea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Zend/tests/property_hooks/foreach.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class ByRef {
2323
}
2424
}
2525
public function __construct() {
26+
$this->undef = 'dynamic';
2627
$this->dynamic = 'dynamic';
28+
unset($this->undef);
2729
}
2830
}
2931

Zend/zend_property_hooks.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,12 @@ static void zho_dynamic_it_fetch_current(zend_object_iterator *iter)
169169
HashPosition pos = zend_hash_iterator_pos(hooked_iter->dynamic_prop_it, properties);
170170

171171
Bucket *bucket = properties->arData + pos;
172+
173+
if (UNEXPECTED(Z_TYPE(bucket->val) == IS_UNDEF)) {
174+
return;
175+
}
176+
172177
if (hooked_iter->by_ref && Z_TYPE(bucket->val) != IS_REFERENCE) {
173-
ZEND_ASSERT(Z_TYPE(bucket->val) != IS_UNDEF);
174178
ZVAL_MAKE_REF(&bucket->val);
175179
}
176180
ZVAL_COPY(&hooked_iter->current_data, &bucket->val);

0 commit comments

Comments
 (0)