Skip to content

Commit d462cba

Browse files
committed
Merge branch 'master' into fake-scope-const
2 parents 6f56869 + 45215d0 commit d462cba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+677
-390
lines changed

UPGRADING.INTERNALS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,21 @@ PHP 8.5 INTERNALS UPGRADE NOTES
4343
. Added the zend_update_exception_properties() function for instantiating
4444
Exception child classes. It updates the $message, $code, and $previous
4545
properties.
46+
. zend_exception_get_default() was removed, use zend_ce_exception directly.
47+
. zend_get_error_exception() was removed, use zend_ce_error_exception
48+
directly.
4649
. ZEND_IS_XDIGIT() macro was removed because it was unused and its name
4750
did not match its actual behavior.
4851
. zend_register_constant() now returns a pointer to the added constant
4952
on success and NULL on failure instead of SUCCESS/FAILURE.
53+
The specialized registration methods that previously had void returns
54+
also return pointers to the added constants:
55+
* zend_register_bool_constant()
56+
* zend_register_null_constant()
57+
* zend_register_long_constant()
58+
* zend_register_double_constant()
59+
* zend_register_string_constant()
60+
* zend_register_stringl_constant()
5061

5162
========================
5263
2. Build system changes

Zend/zend_API.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,13 +4022,11 @@ static zend_always_inline bool zend_is_callable_check_func(zval *callable, zend_
40224022
((fcc->object && fcc->calling_scope->__call) ||
40234023
(!fcc->object && fcc->calling_scope->__callstatic)))) {
40244024
scope = get_scope(frame);
4025-
if (fcc->function_handler->common.scope != scope) {
4026-
if ((fcc->function_handler->common.fn_flags & ZEND_ACC_PRIVATE)
4027-
|| !zend_check_protected(zend_get_function_root_class(fcc->function_handler), scope)) {
4028-
retval = 0;
4029-
fcc->function_handler = NULL;
4030-
goto get_function_via_handler;
4031-
}
4025+
ZEND_ASSERT(!(fcc->function_handler->common.fn_flags & ZEND_ACC_PUBLIC));
4026+
if (!zend_check_method_accessible(fcc->function_handler, scope)) {
4027+
retval = 0;
4028+
fcc->function_handler = NULL;
4029+
goto get_function_via_handler;
40324030
}
40334031
}
40344032
} else {
@@ -4087,17 +4085,15 @@ static zend_always_inline bool zend_is_callable_check_func(zval *callable, zend_
40874085
if (retval
40884086
&& !(fcc->function_handler->common.fn_flags & ZEND_ACC_PUBLIC)) {
40894087
scope = get_scope(frame);
4090-
if (fcc->function_handler->common.scope != scope) {
4091-
if ((fcc->function_handler->common.fn_flags & ZEND_ACC_PRIVATE)
4092-
|| (!zend_check_protected(zend_get_function_root_class(fcc->function_handler), scope))) {
4093-
if (error) {
4094-
if (*error) {
4095-
efree(*error);
4096-
}
4097-
zend_spprintf(error, 0, "cannot access %s method %s::%s()", zend_visibility_string(fcc->function_handler->common.fn_flags), ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
4088+
ZEND_ASSERT(!(fcc->function_handler->common.fn_flags & ZEND_ACC_PUBLIC));
4089+
if (!zend_check_method_accessible(fcc->function_handler, scope)) {
4090+
if (error) {
4091+
if (*error) {
4092+
efree(*error);
40984093
}
4099-
retval = 0;
4094+
zend_spprintf(error, 0, "cannot access %s method %s::%s()", zend_visibility_string(fcc->function_handler->common.fn_flags), ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
41004095
}
4096+
retval = 0;
41014097
}
41024098
}
41034099
}

Zend/zend_ast.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,21 +1098,14 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
10981098
} else {
10991099
fptr = zend_hash_find_ptr_lc(&ce->function_table, method_name);
11001100
if (fptr) {
1101-
if (!(fptr->common.fn_flags & ZEND_ACC_PUBLIC)) {
1102-
if (UNEXPECTED(fptr->common.scope != scope)) {
1103-
if (
1104-
UNEXPECTED(fptr->op_array.fn_flags & ZEND_ACC_PRIVATE)
1105-
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fptr), scope))
1106-
) {
1107-
if (ce->__callstatic) {
1108-
zend_throw_error(NULL, "Creating a callable for the magic __callStatic() method is not supported in constant expressions");
1109-
} else {
1110-
zend_bad_method_call(fptr, method_name, scope);
1111-
}
1112-
1113-
return FAILURE;
1114-
}
1101+
if (!zend_check_method_accessible(fptr, scope)) {
1102+
if (ce->__callstatic) {
1103+
zend_throw_error(NULL, "Creating a callable for the magic __callStatic() method is not supported in constant expressions");
1104+
} else {
1105+
zend_bad_method_call(fptr, method_name, scope);
11151106
}
1107+
1108+
return FAILURE;
11161109
}
11171110
} else {
11181111
if (ce->__callstatic) {

Zend/zend_builtin_functions.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,9 @@ ZEND_FUNCTION(clone)
8989
RETURN_THROWS();
9090
}
9191

92-
if (clone && !(clone->common.fn_flags & ZEND_ACC_PUBLIC)) {
93-
if (clone->common.scope != scope) {
94-
if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE)
95-
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) {
96-
zend_bad_method_call(clone, clone->common.function_name, scope);
97-
RETURN_THROWS();
98-
}
99-
}
92+
if (clone && !zend_check_method_accessible(clone, scope)) {
93+
zend_bad_method_call(clone, clone->common.function_name, scope);
94+
RETURN_THROWS();
10095
}
10196

10297
zend_object *cloned;
@@ -953,13 +948,7 @@ ZEND_FUNCTION(get_class_methods)
953948
scope = zend_get_executed_scope();
954949

955950
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) {
956-
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
957-
|| (scope &&
958-
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
959-
zend_check_protected(mptr->common.scope, scope))
960-
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
961-
scope == mptr->common.scope)))
962-
) {
951+
if (zend_check_method_accessible(mptr, scope)) {
963952
ZVAL_STR_COPY(&method_name, mptr->common.function_name);
964953
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
965954
}

Zend/zend_constants.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,62 +136,62 @@ void zend_register_standard_constants(void)
136136
null_const = zend_hash_str_find_ptr(EG(zend_constants), "NULL", sizeof("NULL")-1);
137137
}
138138

139-
ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number)
139+
ZEND_API zend_constant *zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number)
140140
{
141141
zend_constant c;
142142

143143
ZVAL_NULL(&c.value);
144144
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
145145
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
146-
zend_register_constant(&c);
146+
return zend_register_constant(&c);
147147
}
148148

149-
ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number)
149+
ZEND_API zend_constant *zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number)
150150
{
151151
zend_constant c;
152152

153153
ZVAL_BOOL(&c.value, bval);
154154
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
155155
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
156-
zend_register_constant(&c);
156+
return zend_register_constant(&c);
157157
}
158158

159-
ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number)
159+
ZEND_API zend_constant *zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number)
160160
{
161161
zend_constant c;
162162

163163
ZVAL_LONG(&c.value, lval);
164164
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
165165
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
166-
zend_register_constant(&c);
166+
return zend_register_constant(&c);
167167
}
168168

169169

170-
ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number)
170+
ZEND_API zend_constant *zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number)
171171
{
172172
zend_constant c;
173173

174174
ZVAL_DOUBLE(&c.value, dval);
175175
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
176176
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
177-
zend_register_constant(&c);
177+
return zend_register_constant(&c);
178178
}
179179

180180

181-
ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number)
181+
ZEND_API zend_constant *zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number)
182182
{
183183
zend_constant c;
184184

185185
ZVAL_STR(&c.value, zend_string_init_interned(strval, strlen, flags & CONST_PERSISTENT));
186186
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
187187
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
188-
zend_register_constant(&c);
188+
return zend_register_constant(&c);
189189
}
190190

191191

192-
ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number)
192+
ZEND_API zend_constant *zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number)
193193
{
194-
zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number);
194+
return zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number);
195195
}
196196

197197
static zend_constant *zend_get_halt_offset_constant(const char *name, size_t name_len)

Zend/zend_constants.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ ZEND_API zend_constant *zend_get_constant_ptr(zend_string *name);
9191
ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len);
9292
ZEND_API zval *zend_get_constant_ex(zend_string *name, zend_class_entry *scope, uint32_t flags);
9393
ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *constant_name, zend_class_entry *scope, uint32_t flags);
94-
ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number);
95-
ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number);
96-
ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number);
97-
ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number);
98-
ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
99-
ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
94+
ZEND_API zend_constant *zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number);
95+
ZEND_API zend_constant *zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number);
96+
ZEND_API zend_constant *zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number);
97+
ZEND_API zend_constant *zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number);
98+
ZEND_API zend_constant *zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
99+
ZEND_API zend_constant *zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
100100
ZEND_API zend_constant *zend_register_constant(zend_constant *c);
101101
void zend_constant_add_attributes(zend_constant *c, HashTable *attributes);
102102
#ifdef ZTS

Zend/zend_constants_arginfo.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_exceptions.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -846,20 +846,6 @@ void zend_register_default_exception(void) /* {{{ */
846846
}
847847
/* }}} */
848848

849-
/* {{{ Deprecated - Use zend_ce_exception directly instead */
850-
ZEND_API zend_class_entry *zend_exception_get_default(void)
851-
{
852-
return zend_ce_exception;
853-
}
854-
/* }}} */
855-
856-
/* {{{ Deprecated - Use zend_ce_error_exception directly instead */
857-
ZEND_API zend_class_entry *zend_get_error_exception(void)
858-
{
859-
return zend_ce_error_exception;
860-
}
861-
/* }}} */
862-
863849
static zend_object *zend_throw_exception_zstr(zend_class_entry *exception_ce, zend_string *message, zend_long code) /* {{{ */
864850
{
865851
zval ex, tmp;

Zend/zend_exceptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ void zend_register_default_exception(void);
5050

5151
ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object);
5252

53-
/* Deprecated - Use zend_ce_exception directly instead */
54-
ZEND_API zend_class_entry *zend_exception_get_default(void);
55-
56-
/* Deprecated - Use zend_ce_error_exception directly instead */
57-
ZEND_API zend_class_entry *zend_get_error_exception(void);
58-
5953
ZEND_API void zend_register_default_classes(void);
6054

6155
/* exception_ce NULL, zend_ce_exception, zend_ce_error, or a derived class

Zend/zend_ini_scanner.l

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,16 @@ restart:
352352
/*!re2c
353353
re2c:yyfill:check = 0;
354354
LNUM [0-9]+
355-
DNUM ([0-9]*[\.][0-9]+)|([0-9]+[\.][0-9]*)
355+
DNUM ([0-9]*[.][0-9]+)|([0-9]+[.][0-9]*)
356356
NUMBER [-]?{LNUM}|{DNUM}
357357
ANY_CHAR (.|[\n\t])
358358
NEWLINE ("\r"|"\n"|"\r\n")
359359
TABS_AND_SPACES [ \t]
360360
WHITESPACE [ \t]+
361361
CONSTANT [a-zA-Z_][a-zA-Z0-9_]*
362-
LABEL_CHAR [^=\n\r\t;&|^$~(){}!"\[\]\x00]
362+
LABEL_CHAR [^=\n\r\t;&|^$~(){}!"[\]\x00]
363363
LABEL ({LABEL_CHAR}+)
364-
TOKENS [:,.\[\]"'()&|^+-/*=%$!~<>?@{}]
364+
TOKENS [:,.[\]"'()&|^+-/*=%$!~<>?@{}]
365365
OPERATORS [&|^~()!]
366366
DOLLAR_CURLY "${"
367367

0 commit comments

Comments
 (0)