Skip to content

Commit 4182813

Browse files
committed
Call cast_object handler from get_properties_for
Fixes GH-11547 Closes GH-11583
1 parent 127ad70 commit 4182813

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

UPGRADING.INTERNALS

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PHP 8.3 INTERNALS UPGRADE NOTES
7070
* _php_stream_dirent now has an extra d_type field that is used to store the
7171
directory entry type. This can be used to avoid additional stat calls for
7272
types when the type is already known.
73+
* zend_std_get_properties_for now calls the cast_object handler when casting
74+
objects to arrays.
7375

7476
========================
7577
2. Build system changes

Zend/zend_object_handlers.c

+10
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,16 @@ ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purp
19751975
}
19761976
ZEND_FALLTHROUGH;
19771977
case ZEND_PROP_PURPOSE_ARRAY_CAST:
1978+
if (obj->handlers->cast_object != std_object_handlers.cast_object) {
1979+
zval result;
1980+
if (obj->handlers->cast_object(obj, &result, IS_ARRAY) == SUCCESS) {
1981+
return Z_ARRVAL(result);
1982+
}
1983+
if (EG(exception)) {
1984+
return NULL;
1985+
}
1986+
}
1987+
ZEND_FALLTHROUGH;
19781988
case ZEND_PROP_PURPOSE_SERIALIZE:
19791989
case ZEND_PROP_PURPOSE_VAR_EXPORT:
19801990
case ZEND_PROP_PURPOSE_JSON:

ext/com_dotnet/com_handlers.c

+4
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ static int com_objects_compare(zval *object1, zval *object2)
431431

432432
static zend_result com_object_cast(zend_object *readobj, zval *writeobj, int type)
433433
{
434+
if (type == IS_ARRAY) {
435+
return FAILURE;
436+
}
437+
434438
php_com_dotnet_object *obj;
435439
VARIANT v;
436440
VARTYPE vt = VT_EMPTY;

ext/simplexml/simplexml.c

+1
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,7 @@ static zend_result cast_object(zval *object, int type, char *contents)
18191819
convert_scalar_to_number(object);
18201820
break;
18211821
default:
1822+
zval_ptr_dtor_nogc(object);
18221823
return FAILURE;
18231824
}
18241825
return SUCCESS;

0 commit comments

Comments
 (0)