|
31 | 31 | #include "spl_functions.h" /* For spl_set_private_debug_info_property() */
|
32 | 32 |
|
33 | 33 | /* Defined later in the file */
|
34 |
| -static zend_object_handlers spl_handler_ArrayIterator; |
35 | 34 | PHPAPI zend_class_entry *spl_ce_ArrayIterator;
|
36 | 35 | PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator;
|
37 | 36 |
|
@@ -162,11 +161,18 @@ static zend_object *spl_array_object_new_ex(zend_class_entry *class_type, zend_o
|
162 | 161 | if (clone_orig) {
|
163 | 162 | if (other->ar_flags & SPL_ARRAY_IS_SELF) {
|
164 | 163 | ZVAL_UNDEF(&intern->array);
|
165 |
| - } else if (orig->handlers == &spl_handler_ArrayObject) { |
| 164 | + } else if (instanceof_function(class_type, spl_ce_ArrayObject)) { |
166 | 165 | ZVAL_ARR(&intern->array,
|
167 | 166 | zend_array_dup(spl_array_get_hash_table(other)));
|
168 | 167 | } else {
|
169 |
| - ZEND_ASSERT(orig->handlers == &spl_handler_ArrayIterator); |
| 168 | + #if ZEND_DEBUG |
| 169 | + /* This is because the call to instanceof_function will remain because |
| 170 | + * the compiler can't prove in this compile unit that this function is |
| 171 | + * side-effect-free. |
| 172 | + * See https://github.com/php/php-src/pull/14518#discussion_r1638740932 */ |
| 173 | + ZEND_ASSERT(instanceof_function(class_type, spl_ce_ArrayIterator)); |
| 174 | + #endif |
| 175 | + |
170 | 176 | ZVAL_OBJ_COPY(&intern->array, orig);
|
171 | 177 | intern->ar_flags |= SPL_ARRAY_USE_OTHER;
|
172 | 178 | }
|
@@ -947,7 +953,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
|
947 | 953 | }
|
948 | 954 | }
|
949 | 955 | } else {
|
950 |
| - if (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator) { |
| 956 | + if (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject) { |
951 | 957 | zval_ptr_dtor(&intern->array);
|
952 | 958 | if (just_array) {
|
953 | 959 | spl_array_object *other = Z_SPLARRAY_P(array);
|
@@ -1895,11 +1901,9 @@ PHP_MINIT_FUNCTION(spl_array)
|
1895 | 1901 |
|
1896 | 1902 | spl_ce_ArrayIterator = register_class_ArrayIterator(spl_ce_SeekableIterator, zend_ce_arrayaccess, zend_ce_serializable, zend_ce_countable);
|
1897 | 1903 | spl_ce_ArrayIterator->create_object = spl_array_object_new;
|
1898 |
| - spl_ce_ArrayIterator->default_object_handlers = &spl_handler_ArrayIterator; |
| 1904 | + spl_ce_ArrayIterator->default_object_handlers = &spl_handler_ArrayObject; |
1899 | 1905 | spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator;
|
1900 | 1906 |
|
1901 |
| - memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers)); |
1902 |
| - |
1903 | 1907 | spl_ce_RecursiveArrayIterator = register_class_RecursiveArrayIterator(spl_ce_ArrayIterator, spl_ce_RecursiveIterator);
|
1904 | 1908 | spl_ce_RecursiveArrayIterator->create_object = spl_array_object_new;
|
1905 | 1909 | spl_ce_RecursiveArrayIterator->get_iterator = spl_array_get_iterator;
|
|
0 commit comments