Skip to content

Commit 8ccdb82

Browse files
committed
Merge branch 'PHP-7.4'
2 parents 6b7545c + 5456a6e commit 8ccdb82

File tree

1 file changed

+74
-149
lines changed

1 file changed

+74
-149
lines changed

Zend/zend_builtin_functions.c

Lines changed: 74 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
298298
/* }}} */
299299

300300
zend_module_entry zend_builtin_module = { /* {{{ */
301-
STANDARD_MODULE_HEADER,
301+
STANDARD_MODULE_HEADER,
302302
"Core",
303303
builtin_functions,
304304
ZEND_MINIT(core),
@@ -933,7 +933,7 @@ ZEND_FUNCTION(get_parent_class)
933933
if (Z_TYPE_P(arg) == IS_OBJECT) {
934934
ce = Z_OBJ_P(arg)->ce;
935935
} else if (Z_TYPE_P(arg) == IS_STRING) {
936-
ce = zend_lookup_class(Z_STR_P(arg));
936+
ce = zend_lookup_class(Z_STR_P(arg));
937937
}
938938

939939
if (ce && ce->parent) {
@@ -1021,9 +1021,9 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int st
10211021

10221022
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
10231023
if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
1024-
!zend_check_protected(prop_info->ce, scope)) ||
1025-
((prop_info->flags & ZEND_ACC_PRIVATE) &&
1026-
prop_info->ce != scope)) {
1024+
!zend_check_protected(prop_info->ce, scope)) ||
1025+
((prop_info->flags & ZEND_ACC_PRIVATE) &&
1026+
prop_info->ce != scope)) {
10271027
continue;
10281028
}
10291029
prop = NULL;
@@ -1189,7 +1189,7 @@ ZEND_FUNCTION(get_class_methods)
11891189
if (Z_TYPE_P(klass) == IS_OBJECT) {
11901190
ce = Z_OBJCE_P(klass);
11911191
} else if (Z_TYPE_P(klass) == IS_STRING) {
1192-
ce = zend_lookup_class(Z_STR_P(klass));
1192+
ce = zend_lookup_class(Z_STR_P(klass));
11931193
}
11941194

11951195
if (!ce) {
@@ -1203,10 +1203,10 @@ ZEND_FUNCTION(get_class_methods)
12031203

12041204
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
12051205
|| (scope &&
1206-
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
1207-
zend_check_protected(mptr->common.scope, scope))
1206+
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
1207+
zend_check_protected(mptr->common.scope, scope))
12081208
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
1209-
scope == mptr->common.scope)))
1209+
scope == mptr->common.scope)))
12101210
) {
12111211
if (mptr->type == ZEND_USER_FUNCTION &&
12121212
(!mptr->op_array.refcount || *mptr->op_array.refcount > 1) &&
@@ -1317,114 +1317,63 @@ ZEND_FUNCTION(property_exists)
13171317
}
13181318
/* }}} */
13191319

1320-
/* {{{ proto bool class_exists(string classname [, bool autoload])
1321-
Checks if the class exists */
1322-
ZEND_FUNCTION(class_exists)
1320+
static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
13231321
{
1324-
zend_string *class_name;
1325-
zend_string *lc_name;
1322+
zend_string *name;
1323+
zend_string *lcname;
13261324
zend_class_entry *ce;
13271325
zend_bool autoload = 1;
13281326

13291327
ZEND_PARSE_PARAMETERS_START(1, 2)
1330-
Z_PARAM_STR(class_name)
1328+
Z_PARAM_STR(name)
13311329
Z_PARAM_OPTIONAL
13321330
Z_PARAM_BOOL(autoload)
13331331
ZEND_PARSE_PARAMETERS_END();
13341332

13351333
if (!autoload) {
1336-
if (ZSTR_VAL(class_name)[0] == '\\') {
1334+
if (ZSTR_VAL(name)[0] == '\\') {
13371335
/* Ignore leading "\" */
1338-
lc_name = zend_string_alloc(ZSTR_LEN(class_name) - 1, 0);
1339-
zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(class_name) + 1, ZSTR_LEN(class_name) - 1);
1336+
lcname = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
1337+
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
13401338
} else {
1341-
lc_name = zend_string_tolower(class_name);
1339+
lcname = zend_string_tolower(name);
13421340
}
13431341

1344-
ce = zend_hash_find_ptr(EG(class_table), lc_name);
1345-
zend_string_release_ex(lc_name, 0);
1342+
ce = zend_hash_find_ptr(EG(class_table), lcname);
1343+
zend_string_release_ex(lcname, 0);
13461344
} else {
1347-
ce = zend_lookup_class(class_name);
1345+
ce = zend_lookup_class(name);
13481346
}
13491347

13501348
if (ce) {
1351-
RETURN_BOOL((ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) == 0);
1349+
RETURN_BOOL((flags == 0 || (ce->ce_flags & flags)) && !(ce->ce_flags & skip_flags));
13521350
} else {
13531351
RETURN_FALSE;
13541352
}
13551353
}
1354+
/* {{{ */
1355+
1356+
/* {{{ proto bool class_exists(string classname [, bool autoload])
1357+
Checks if the class exists */
1358+
ZEND_FUNCTION(class_exists)
1359+
{
1360+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
1361+
}
13561362
/* }}} */
13571363

13581364
/* {{{ proto bool interface_exists(string classname [, bool autoload])
13591365
Checks if the class exists */
13601366
ZEND_FUNCTION(interface_exists)
13611367
{
1362-
zend_string *iface_name, *lc_name;
1363-
zend_class_entry *ce;
1364-
zend_bool autoload = 1;
1365-
1366-
ZEND_PARSE_PARAMETERS_START(1, 2)
1367-
Z_PARAM_STR(iface_name)
1368-
Z_PARAM_OPTIONAL
1369-
Z_PARAM_BOOL(autoload)
1370-
ZEND_PARSE_PARAMETERS_END();
1371-
1372-
if (!autoload) {
1373-
if (ZSTR_VAL(iface_name)[0] == '\\') {
1374-
/* Ignore leading "\" */
1375-
lc_name = zend_string_alloc(ZSTR_LEN(iface_name) - 1, 0);
1376-
zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(iface_name) + 1, ZSTR_LEN(iface_name) - 1);
1377-
} else {
1378-
lc_name = zend_string_tolower(iface_name);
1379-
}
1380-
ce = zend_hash_find_ptr(EG(class_table), lc_name);
1381-
zend_string_release_ex(lc_name, 0);
1382-
RETURN_BOOL(ce && ce->ce_flags & ZEND_ACC_INTERFACE);
1383-
}
1384-
1385-
ce = zend_lookup_class(iface_name);
1386-
if (ce) {
1387-
RETURN_BOOL((ce->ce_flags & ZEND_ACC_INTERFACE) > 0);
1388-
} else {
1389-
RETURN_FALSE;
1390-
}
1368+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE, 0);
13911369
}
13921370
/* }}} */
13931371

13941372
/* {{{ proto bool trait_exists(string traitname [, bool autoload])
13951373
Checks if the trait exists */
13961374
ZEND_FUNCTION(trait_exists)
13971375
{
1398-
zend_string *trait_name, *lc_name;
1399-
zend_class_entry *ce;
1400-
zend_bool autoload = 1;
1401-
1402-
ZEND_PARSE_PARAMETERS_START(1, 2)
1403-
Z_PARAM_STR(trait_name)
1404-
Z_PARAM_OPTIONAL
1405-
Z_PARAM_BOOL(autoload)
1406-
ZEND_PARSE_PARAMETERS_END();
1407-
1408-
if (!autoload) {
1409-
if (ZSTR_VAL(trait_name)[0] == '\\') {
1410-
/* Ignore leading "\" */
1411-
lc_name = zend_string_alloc(ZSTR_LEN(trait_name) - 1, 0);
1412-
zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(trait_name) + 1, ZSTR_LEN(trait_name) - 1);
1413-
} else {
1414-
lc_name = zend_string_tolower(trait_name);
1415-
}
1416-
1417-
ce = zend_hash_find_ptr(EG(class_table), lc_name);
1418-
zend_string_release_ex(lc_name, 0);
1419-
} else {
1420-
ce = zend_lookup_class(trait_name);
1421-
}
1422-
1423-
if (ce) {
1424-
RETURN_BOOL((ce->ce_flags & ZEND_ACC_TRAIT) != 0);
1425-
} else {
1426-
RETURN_FALSE;
1427-
}
1376+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT, 0);
14281377
}
14291378
/* }}} */
14301379

@@ -1671,16 +1620,14 @@ ZEND_FUNCTION(restore_exception_handler)
16711620
static void copy_class_or_interface_name(zval *array, zend_string *key, zend_class_entry *ce) /* {{{ */
16721621
{
16731622
if ((ce->refcount == 1 && !(ce->ce_flags & ZEND_ACC_IMMUTABLE)) ||
1674-
same_name(key, ce->name)) {
1623+
same_name(key, ce->name)) {
16751624
key = ce->name;
16761625
}
16771626
add_next_index_str(array, zend_string_copy(key));
16781627
}
16791628
/* }}} */
16801629

1681-
/* {{{ proto array get_declared_traits()
1682-
Returns an array of all declared traits. */
1683-
ZEND_FUNCTION(get_declared_traits)
1630+
static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
16841631
{
16851632
zend_string *key;
16861633
zend_class_entry *ce;
@@ -1693,55 +1640,35 @@ ZEND_FUNCTION(get_declared_traits)
16931640
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) {
16941641
if (key
16951642
&& ZSTR_VAL(key)[0] != 0
1696-
&& (ce->ce_flags & ZEND_ACC_TRAIT)) {
1643+
&& (ce->ce_flags & flags)
1644+
&& !(ce->ce_flags & skip_flags)) {
16971645
copy_class_or_interface_name(return_value, key, ce);
16981646
}
16991647
} ZEND_HASH_FOREACH_END();
17001648
}
1649+
/* {{{ */
1650+
1651+
/* {{{ proto array get_declared_traits()
1652+
Returns an array of all declared traits. */
1653+
ZEND_FUNCTION(get_declared_traits)
1654+
{
1655+
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT, 0);
1656+
}
17011657
/* }}} */
17021658

17031659
/* {{{ proto array get_declared_classes()
17041660
Returns an array of all declared classes. */
17051661
ZEND_FUNCTION(get_declared_classes)
17061662
{
1707-
zend_string *key;
1708-
zend_class_entry *ce;
1709-
1710-
if (zend_parse_parameters_none() == FAILURE) {
1711-
return;
1712-
}
1713-
1714-
array_init(return_value);
1715-
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) {
1716-
if (key
1717-
&& ZSTR_VAL(key)[0] != 0
1718-
&& !(ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT))
1719-
&& (ce->ce_flags & ZEND_ACC_LINKED)) {
1720-
copy_class_or_interface_name(return_value, key, ce);
1721-
}
1722-
} ZEND_HASH_FOREACH_END();
1663+
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
17231664
}
17241665
/* }}} */
17251666

17261667
/* {{{ proto array get_declared_interfaces()
17271668
Returns an array of all declared interfaces. */
17281669
ZEND_FUNCTION(get_declared_interfaces)
17291670
{
1730-
zend_string *key;
1731-
zend_class_entry *ce;
1732-
1733-
if (zend_parse_parameters_none() == FAILURE) {
1734-
return;
1735-
}
1736-
1737-
array_init(return_value);
1738-
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) {
1739-
if (key
1740-
&& ZSTR_VAL(key)[0] != 0
1741-
&& (ce->ce_flags & ZEND_ACC_INTERFACE)) {
1742-
copy_class_or_interface_name(return_value, key, ce);
1743-
}
1744-
} ZEND_HASH_FOREACH_END();
1671+
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE, 0);
17451672
}
17461673
/* }}} */
17471674

@@ -2070,6 +1997,20 @@ void debug_print_backtrace_args(zval *arg_array) /* {{{ */
20701997
}
20711998
/* }}} */
20721999

2000+
static inline zend_bool skip_internal_handler(zend_execute_data *skip) /* {{{ */
2001+
{
2002+
return !(skip->func && ZEND_USER_CODE(skip->func->common.type))
2003+
&& skip->prev_execute_data
2004+
&& skip->prev_execute_data->func
2005+
&& ZEND_USER_CODE(skip->prev_execute_data->func->common.type)
2006+
&& skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL
2007+
&& skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL
2008+
&& skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL
2009+
&& skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME
2010+
&& skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL;
2011+
}
2012+
/* {{{ */
2013+
20732014
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
20742015
ZEND_FUNCTION(debug_print_backtrace)
20752016
{
@@ -2108,15 +2049,7 @@ ZEND_FUNCTION(debug_print_backtrace)
21082049

21092050
skip = ptr;
21102051
/* skip internal handler */
2111-
if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
2112-
skip->prev_execute_data &&
2113-
skip->prev_execute_data->func &&
2114-
ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
2115-
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
2116-
skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL &&
2117-
skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL &&
2118-
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
2119-
skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
2052+
if (skip_internal_handler(skip)) {
21202053
skip = skip->prev_execute_data;
21212054
}
21222055

@@ -2143,16 +2076,16 @@ ZEND_FUNCTION(debug_print_backtrace)
21432076
zend_string *zend_function_name;
21442077

21452078
func = call->func;
2146-
if (func->common.scope && func->common.scope->trait_aliases) {
2147-
zend_function_name = zend_resolve_method_name(object ? object->ce : func->common.scope, func);
2148-
} else {
2149-
zend_function_name = func->common.function_name;
2150-
}
2151-
if (zend_function_name != NULL) {
2152-
function_name = ZSTR_VAL(zend_function_name);
2153-
} else {
2154-
function_name = NULL;
2155-
}
2079+
if (func->common.scope && func->common.scope->trait_aliases) {
2080+
zend_function_name = zend_resolve_method_name(object ? object->ce : func->common.scope, func);
2081+
} else {
2082+
zend_function_name = func->common.function_name;
2083+
}
2084+
if (zend_function_name != NULL) {
2085+
function_name = ZSTR_VAL(zend_function_name);
2086+
} else {
2087+
function_name = NULL;
2088+
}
21562089
} else {
21572090
func = NULL;
21582091
function_name = NULL;
@@ -2244,7 +2177,7 @@ ZEND_FUNCTION(debug_print_backtrace)
22442177

22452178
while (prev) {
22462179
if (prev_call &&
2247-
prev_call->func &&
2180+
prev_call->func &&
22482181
!ZEND_USER_CODE(prev_call->func->common.type)) {
22492182
prev = NULL;
22502183
break;
@@ -2317,15 +2250,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
23172250

23182251
skip = ptr;
23192252
/* skip internal handler */
2320-
if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
2321-
skip->prev_execute_data &&
2322-
skip->prev_execute_data->func &&
2323-
ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
2324-
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
2325-
skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL &&
2326-
skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL &&
2327-
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
2328-
skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
2253+
if (skip_internal_handler(skip)) {
23292254
skip = skip->prev_execute_data;
23302255
}
23312256

@@ -2354,7 +2279,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
23542279

23552280
while (prev) {
23562281
if (prev_call &&
2357-
prev_call->func &&
2282+
prev_call->func &&
23582283
!ZEND_USER_CODE(prev_call->func->common.type) &&
23592284
!(prev_call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
23602285
break;
@@ -2378,7 +2303,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
23782303
if (call && call->func) {
23792304
func = call->func;
23802305
function_name = (func->common.scope &&
2381-
func->common.scope->trait_aliases) ?
2306+
func->common.scope->trait_aliases) ?
23822307
zend_resolve_method_name(
23832308
(object ? object->ce : func->common.scope), func) :
23842309
func->common.function_name;

0 commit comments

Comments
 (0)