Skip to content

Commit 68596ed

Browse files
committed
Fix copying of functions in variance obligations
Only copy sizeof(zend_internal_function) for internal functions.
1 parent a73f98e commit 68596ed

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Internal class as parent
3+
--FILE--
4+
<?php
5+
6+
class Test extends DateTime {
7+
public static function createFromFormat($format, $time, Wrong $timezone = null) { }
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Warning: Could not check compatibility between Test::createFromFormat($format, $time, ?Wrong $timezone = NULL) and DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL), because class Wrong is not available in %s on line %d

Zend/zend_inheritance.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,8 +2294,17 @@ static void add_compatibility_obligation(
22942294
HashTable *obligations = get_or_init_obligations_for_class(ce);
22952295
variance_obligation *obligation = emalloc(sizeof(variance_obligation));
22962296
obligation->type = OBLIGATION_COMPATIBILITY;
2297-
obligation->child_fn = *child_fn;
2298-
obligation->parent_fn = *parent_fn;
2297+
/* Copy functions, because they may be stack-allocated in the case of traits. */
2298+
if (child_fn->common.type == ZEND_INTERNAL_FUNCTION) {
2299+
memcpy(&obligation->child_fn, child_fn, sizeof(zend_internal_function));
2300+
} else {
2301+
memcpy(&obligation->child_fn, child_fn, sizeof(zend_op_array));
2302+
}
2303+
if (parent_fn->common.type == ZEND_INTERNAL_FUNCTION) {
2304+
memcpy(&obligation->parent_fn, parent_fn, sizeof(zend_internal_function));
2305+
} else {
2306+
memcpy(&obligation->parent_fn, parent_fn, sizeof(zend_op_array));
2307+
}
22992308
obligation->always_error = always_error;
23002309
zend_hash_next_index_insert_ptr(obligations, obligation);
23012310
}

0 commit comments

Comments
 (0)