Skip to content

Commit 913157f

Browse files
authored
Extract obtaining of fake scope into function (#14960)
1 parent 694e044 commit 913157f

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

Zend/zend_object_handlers.c

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,20 @@ static ZEND_COLD zend_never_inline void zend_readonly_property_unset_error(
316316
ZSTR_VAL(ce->name), ZSTR_VAL(member));
317317
}
318318

319+
static zend_always_inline zend_class_entry *get_fake_or_executed_scope(void)
320+
{
321+
if (UNEXPECTED(EG(fake_scope))) {
322+
return EG(fake_scope);
323+
} else {
324+
return zend_get_executed_scope();
325+
}
326+
}
327+
319328
static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *ce, zend_string *member, int silent, void **cache_slot, const zend_property_info **info_ptr) /* {{{ */
320329
{
321330
zval *zv;
322331
zend_property_info *property_info;
323332
uint32_t flags;
324-
zend_class_entry *scope;
325333
uintptr_t offset;
326334

327335
if (cache_slot && EXPECTED(ce == CACHED_PTR_EX(cache_slot))) {
@@ -349,11 +357,7 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
349357
flags = property_info->flags;
350358

351359
if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
352-
if (UNEXPECTED(EG(fake_scope))) {
353-
scope = EG(fake_scope);
354-
} else {
355-
scope = zend_get_executed_scope();
356-
}
360+
zend_class_entry *scope = get_fake_or_executed_scope();
357361

358362
if (property_info->ce != scope) {
359363
if (flags & ZEND_ACC_CHANGED) {
@@ -436,7 +440,6 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
436440
zval *zv;
437441
zend_property_info *property_info;
438442
uint32_t flags;
439-
zend_class_entry *scope;
440443

441444
if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
442445
|| EXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
@@ -454,11 +457,7 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
454457
flags = property_info->flags;
455458

456459
if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
457-
if (UNEXPECTED(EG(fake_scope))) {
458-
scope = EG(fake_scope);
459-
} else {
460-
scope = zend_get_executed_scope();
461-
}
460+
zend_class_entry *scope = get_fake_or_executed_scope();
462461
if (property_info->ce != scope) {
463462
if (flags & ZEND_ACC_CHANGED) {
464463
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
@@ -917,12 +916,7 @@ static zend_always_inline bool property_uses_strict_types(void) {
917916
static bool verify_readonly_initialization_access(
918917
const zend_property_info *prop_info, const zend_class_entry *ce,
919918
zend_string *name, const char *operation) {
920-
zend_class_entry *scope;
921-
if (UNEXPECTED(EG(fake_scope))) {
922-
scope = EG(fake_scope);
923-
} else {
924-
scope = zend_get_executed_scope();
925-
}
919+
zend_class_entry *scope = get_fake_or_executed_scope();
926920
if (prop_info->ce == scope) {
927921
return true;
928922
}
@@ -1839,7 +1833,6 @@ ZEND_API void zend_class_init_statics(zend_class_entry *class_type) /* {{{ */
18391833
ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend_string *property_name, int type, zend_property_info **property_info_ptr) /* {{{ */
18401834
{
18411835
zval *ret;
1842-
zend_class_entry *scope;
18431836
zend_property_info *property_info = zend_hash_find_ptr(&ce->properties_info, property_name);
18441837
*property_info_ptr = property_info;
18451838

@@ -1848,11 +1841,7 @@ ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend
18481841
}
18491842

18501843
if (!(property_info->flags & ZEND_ACC_PUBLIC)) {
1851-
if (UNEXPECTED(EG(fake_scope))) {
1852-
scope = EG(fake_scope);
1853-
} else {
1854-
scope = zend_get_executed_scope();
1855-
}
1844+
zend_class_entry *scope = get_fake_or_executed_scope();
18561845
if (property_info->ce != scope) {
18571846
if (UNEXPECTED(property_info->flags & ZEND_ACC_PRIVATE)
18581847
|| UNEXPECTED(!is_protected_compatible_scope(property_info->ce, scope))) {
@@ -1933,15 +1922,10 @@ static ZEND_COLD zend_never_inline void zend_bad_constructor_call(zend_function
19331922
ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */
19341923
{
19351924
zend_function *constructor = zobj->ce->constructor;
1936-
zend_class_entry *scope;
19371925

19381926
if (constructor) {
19391927
if (UNEXPECTED(!(constructor->op_array.fn_flags & ZEND_ACC_PUBLIC))) {
1940-
if (UNEXPECTED(EG(fake_scope))) {
1941-
scope = EG(fake_scope);
1942-
} else {
1943-
scope = zend_get_executed_scope();
1944-
}
1928+
zend_class_entry *scope = get_fake_or_executed_scope();
19451929
if (UNEXPECTED(constructor->common.scope != scope)) {
19461930
if (UNEXPECTED(constructor->op_array.fn_flags & ZEND_ACC_PRIVATE)
19471931
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), scope))) {

0 commit comments

Comments
 (0)