Skip to content
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ PHP 8.0, which corresponds to the `PHP-8.0` branch in Git. Please also make sure
you add a link to the PR in the bug on [the bug tracker](https://github.com/php/php-src/issues)
or [the old bug tracker](https://bugs.php.net/).

If you are new to contributing to PHP, issues tagged
[`Good first issue`](https://github.com/php/php-src/labels/Good%20first%20issue)
are suitable for you as a newcomer to file PRs against.

Pull requests implementing RFCs should be submitted against `master`.

Pull requests should *never* be submitted against `PHP-x.y.z` branches, as these
Expand Down
15 changes: 4 additions & 11 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3238,12 +3238,9 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
if (unload) { /* before unloading, display all remaining bad function in the module */
while (ptr->fname) {
fname_len = strlen(ptr->fname);
lowercase_name = zend_string_alloc(fname_len, 0);
zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ptr->fname, fname_len);
if (zend_hash_exists(target_function_table, lowercase_name)) {
if (zend_hash_str_find_ptr_lc(target_function_table, ptr->fname, fname_len) != NULL) {
zend_error(error_type, "Function registration failed - duplicate name - %s%s%s", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
}
zend_string_efree(lowercase_name);
ptr++;
}
zend_unregister_functions(functions, count, target_function_table);
Expand Down Expand Up @@ -3805,7 +3802,6 @@ static zend_always_inline bool zend_is_method_callable(zend_string *callable, co
HashTable *ftable;
bool call_via_handler = false;
zend_class_entry *scope;
zval *zv;

fcc->calling_scope = NULL;

Expand Down Expand Up @@ -3891,19 +3887,16 @@ static zend_always_inline bool zend_is_method_callable(zend_string *callable, co
if (fcc->function_handler) {
retval = true;
}
} else if ((zv = zend_hash_find(ftable, lmname)) != NULL) {
fcc->function_handler = Z_PTR_P(zv);
} else if ((fcc->function_handler = zend_hash_find_ptr(ftable, lmname)) != NULL) {
retval = true;
if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) &&
!strict_class) {
scope = get_scope(frame);
if (scope &&
instanceof_function(fcc->function_handler->common.scope, scope)) {

zv = zend_hash_find(&scope->function_table, lmname);
if (zv != NULL) {
zend_function *priv_fbc = Z_PTR_P(zv);

zend_function *priv_fbc = zend_hash_find_ptr(&scope->function_table, lmname);
if (priv_fbc != NULL) {
if ((priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE)
&& priv_fbc->common.scope == scope) {
fcc->function_handler = priv_fbc;
Expand Down
17 changes: 2 additions & 15 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -5103,7 +5103,6 @@ static void zend_swap_operands(zend_op *op) /* {{{ */
static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_string *function, uint32_t num_args) /* {{{ */
{
zend_function *fbc;
zval *func;
zend_class_entry *called_scope;
zend_string *lcname;
const char *colon;
Expand Down Expand Up @@ -5155,23 +5154,11 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
init_func_run_time_cache(&fbc->op_array);
}
} else {
if (ZSTR_VAL(function)[0] == '\\') {
lcname = zend_string_alloc(ZSTR_LEN(function) - 1, 0);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(function) + 1, ZSTR_LEN(function) - 1);
} else {
lcname = zend_string_tolower(function);
}
if (UNEXPECTED((func = zend_hash_find(EG(function_table), lcname)) == NULL)) {
fbc = zend_fetch_function(function);
if (UNEXPECTED(fbc == NULL)) {
zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function));
zend_string_release_ex(lcname, 0);
return NULL;
}
zend_string_release_ex(lcname, 0);

fbc = Z_FUNC_P(func);
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
init_func_run_time_cache(&fbc->op_array);
}
called_scope = NULL;
}

Expand Down
6 changes: 2 additions & 4 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,6 @@ ZEND_API bool zend_is_valid_class_name(const zend_string *name) {
ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *key, uint32_t flags) /* {{{ */
{
zend_class_entry *ce = NULL;
zval *zv;
zend_string *lc_name;
zend_string *autoload_name;
uint32_t ce_cache = 0;
Expand Down Expand Up @@ -1229,12 +1228,11 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
}
}

zv = zend_hash_find(EG(class_table), lc_name);
if (zv) {
ce = zend_hash_find_ptr(EG(class_table), lc_name);
if (ce) {
if (!key) {
zend_string_release_ex(lc_name, 0);
}
ce = (zend_class_entry*)Z_PTR_P(zv);
if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_LINKED))) {
if ((flags & ZEND_FETCH_CLASS_ALLOW_UNLINKED) ||
((flags & ZEND_FETCH_CLASS_ALLOW_NEARLY_LINKED) &&
Expand Down
56 changes: 18 additions & 38 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,9 @@ static zend_never_inline int is_protected_compatible_scope(const zend_class_entr

static zend_never_inline zend_property_info *zend_get_parent_private_property(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *member) /* {{{ */
{
zval *zv;
zend_property_info *prop_info;

if (scope != ce && scope && is_derived_class(ce, scope)) {
zv = zend_hash_find(&scope->properties_info, member);
if (zv != NULL) {
prop_info = (zend_property_info*)Z_PTR_P(zv);
zend_property_info *prop_info = zend_hash_find_ptr(&scope->properties_info, member);
if (prop_info != NULL) {
if ((prop_info->flags & ZEND_ACC_PRIVATE)
&& prop_info->ce == scope) {
return prop_info;
Expand Down Expand Up @@ -364,7 +360,6 @@ static zend_always_inline const zend_class_entry *get_fake_or_executed_scope(voi

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) /* {{{ */
{
zval *zv;
zend_property_info *property_info;
uint32_t flags;
uintptr_t offset;
Expand All @@ -375,7 +370,7 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
}

if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
|| UNEXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
|| UNEXPECTED((property_info = zend_hash_find_ptr(&ce->properties_info, member)) == NULL)) {
if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0') && ZSTR_LEN(member) != 0) {
if (!silent) {
zend_bad_property_name();
Expand All @@ -390,7 +385,6 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
return ZEND_DYNAMIC_PROPERTY_OFFSET;
}

property_info = (zend_property_info*)Z_PTR_P(zv);
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
Expand Down Expand Up @@ -474,12 +468,11 @@ static ZEND_COLD void zend_wrong_offset(zend_class_entry *ce, zend_string *membe

ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce, zend_string *member, int silent) /* {{{ */
{
zval *zv;
zend_property_info *property_info;
uint32_t flags;

if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
|| EXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
|| EXPECTED((property_info = zend_hash_find_ptr(&ce->properties_info, member)) == NULL)) {
if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0') && ZSTR_LEN(member) != 0) {
if (!silent) {
zend_bad_property_name();
Expand All @@ -490,7 +483,6 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
return NULL;
}

property_info = (zend_property_info*)Z_PTR_P(zv);
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
Expand Down Expand Up @@ -643,9 +635,9 @@ ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *membe
} else if (EXPECTED(Z_TYPE_P(zv) == IS_ARRAY)) {
guards = Z_ARRVAL_P(zv);
ZEND_ASSERT(guards != NULL);
zv = zend_hash_find(guards, member);
if (zv != NULL) {
return (uint32_t*)(((uintptr_t)Z_PTR_P(zv)) & ~1);
void *guard = zend_hash_find_ptr(guards, member);
if (guard != NULL) {
return (uint32_t*)(((uintptr_t)guard) & ~1);
}
} else {
ZEND_ASSERT(Z_TYPE_P(zv) == IS_UNDEF);
Expand Down Expand Up @@ -1756,13 +1748,9 @@ ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{

static zend_never_inline zend_function *zend_get_parent_private_method(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *function_name) /* {{{ */
{
zval *func;
zend_function *fbc;

if (scope != ce && scope && is_derived_class(ce, scope)) {
func = zend_hash_find(&scope->function_table, function_name);
if (func != NULL) {
fbc = Z_FUNC_P(func);
zend_function *fbc = zend_hash_find_ptr(&scope->function_table, function_name);
if (fbc != NULL) {
if ((fbc->common.fn_flags & ZEND_ACC_PRIVATE)
&& fbc->common.scope == scope) {
return fbc;
Expand Down Expand Up @@ -1979,7 +1967,6 @@ ZEND_API ZEND_COLD zend_never_inline void zend_abstract_method_call(const zend_f
ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key) /* {{{ */
{
zend_object *zobj = *obj_ptr;
zval *func;
zend_function *fbc;
zend_string *lc_method_name;
ALLOCA_FLAG(use_heap);
Expand All @@ -1994,7 +1981,8 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
zend_str_tolower_copy(ZSTR_VAL(lc_method_name), ZSTR_VAL(method_name), ZSTR_LEN(method_name));
}

if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
fbc = zend_hash_find_ptr(&zobj->ce->function_table, lc_method_name);
if (UNEXPECTED(fbc == NULL)) {
if (UNEXPECTED(!key)) {
ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
}
Expand All @@ -2005,8 +1993,6 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
}
}

fbc = Z_FUNC_P(func);

/* Check access level */
if (fbc->op_array.fn_flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
const zend_class_entry *scope = zend_get_executed_scope();
Expand Down Expand Up @@ -2067,17 +2053,14 @@ static zend_always_inline zend_function *get_static_method_fallback(

ZEND_API zend_function *zend_std_get_static_method(const zend_class_entry *ce, zend_string *function_name, const zval *key) /* {{{ */
{
zend_string *lc_function_name;
zend_function *fbc;
if (EXPECTED(key != NULL)) {
lc_function_name = Z_STR_P(key);
fbc = zend_hash_find_ptr(&ce->function_table, Z_STR_P(key));
} else {
lc_function_name = zend_string_tolower(function_name);
fbc = zend_hash_find_ptr_lc(&ce->function_table, function_name);
}

zend_function *fbc;
zval *func = zend_hash_find(&ce->function_table, lc_function_name);
if (EXPECTED(func)) {
fbc = Z_FUNC_P(func);
if (EXPECTED(fbc)) {
if (!(fbc->common.fn_flags & ZEND_ACC_PUBLIC)) {
const zend_class_entry *scope = zend_get_executed_scope();
ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_PUBLIC));
Expand All @@ -2093,10 +2076,6 @@ ZEND_API zend_function *zend_std_get_static_method(const zend_class_entry *ce, z
fbc = get_static_method_fallback(ce, function_name);
}

if (UNEXPECTED(!key)) {
zend_string_release_ex(lc_function_name, 0);
}

if (EXPECTED(fbc)) {
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
zend_abstract_method_call(fbc);
Expand Down Expand Up @@ -2636,12 +2615,13 @@ ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *w
ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */
{
zend_class_entry *ce = obj->ce;
const zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
zend_function *func = zend_hash_find_ex_ptr(
&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE), /* known_hash */ true);

if (func == NULL) {
return FAILURE;
}
*fptr_ptr = Z_FUNC_P(func);
*fptr_ptr = func;
*ce_ptr = ce;
*obj_ptr = obj;

Expand Down