Skip to content

Commit a9d99e5

Browse files
committed
Move the instanceof check before the cached path
1 parent 1463f2b commit a9d99e5

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

ext/reflection/php_reflection.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5817,6 +5817,12 @@ ZEND_METHOD(ReflectionProperty, getValue)
58175817
RETURN_THROWS();
58185818
}
58195819

5820+
/* TODO: Should this always use intern->ce? */
5821+
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
5822+
_DO_THROW("Given object is not an instance of the class this property was declared in");
5823+
RETURN_THROWS();
5824+
}
5825+
58205826
if (ref->cache_slot[0] == Z_OBJCE_P(object)) {
58215827
uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1];
58225828

@@ -5826,12 +5832,6 @@ ZEND_METHOD(ReflectionProperty, getValue)
58265832
RETURN_COPY_DEREF(retval);
58275833
}
58285834
}
5829-
} else {
5830-
/* TODO: Should this always use intern->ce? */
5831-
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
5832-
_DO_THROW("Given object is not an instance of the class this property was declared in");
5833-
RETURN_THROWS();
5834-
}
58355835
}
58365836

58375837
zend_class_entry *old_scope = EG(fake_scope);
@@ -5926,6 +5926,11 @@ ZEND_METHOD(ReflectionProperty, getRawValue)
59265926

59275927
GET_REFLECTION_OBJECT_PTR(ref);
59285928

5929+
if (!instanceof_function(Z_OBJCE_P(object), intern->ce)) {
5930+
_DO_THROW("Given object is not an instance of the class this property was declared in");
5931+
RETURN_THROWS();
5932+
}
5933+
59295934
if (ref->cache_slot[0] == Z_OBJCE_P(object)) {
59305935
uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1];
59315936

@@ -5935,11 +5940,6 @@ ZEND_METHOD(ReflectionProperty, getRawValue)
59355940
RETURN_COPY_DEREF(retval);
59365941
}
59375942
}
5938-
} else {
5939-
if (!instanceof_function(Z_OBJCE_P(object), intern->ce)) {
5940-
_DO_THROW("Given object is not an instance of the class this property was declared in");
5941-
RETURN_THROWS();
5942-
}
59435943
}
59445944

59455945
zend_property_info *prop = reflection_property_get_effective_prop(ref,
@@ -6209,19 +6209,19 @@ ZEND_METHOD(ReflectionProperty, isInitialized)
62096209
RETURN_THROWS();
62106210
}
62116211

6212+
/* TODO: Should this always use intern->ce? */
6213+
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
6214+
_DO_THROW("Given object is not an instance of the class this property was declared in");
6215+
RETURN_THROWS();
6216+
}
6217+
62126218
if (ref->cache_slot[0] == Z_OBJCE_P(object)) {
62136219
uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1];
62146220

62156221
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
62166222
zval *value = OBJ_PROP(Z_OBJ_P(object), prop_offset);
62176223
RETURN_BOOL(Z_TYPE_INFO_P(value) != IS_UNDEF);
62186224
}
6219-
} else {
6220-
/* TODO: Should this always use intern->ce? */
6221-
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
6222-
_DO_THROW("Given object is not an instance of the class this property was declared in");
6223-
RETURN_THROWS();
6224-
}
62256225
}
62266226

62276227
old_scope = EG(fake_scope);

0 commit comments

Comments
 (0)