Skip to content

Commit ca50aa9

Browse files
committed
Merge branch 'master' of git.php.net:php-src
2 parents b1f4f5c + 88dd38e commit ca50aa9

File tree

5 files changed

+123
-126
lines changed

5 files changed

+123
-126
lines changed

Zend/zend_constants.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -478,56 +478,6 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
478478
return &c->value;
479479
}
480480

481-
ZEND_API zend_constant* ZEND_FASTCALL zend_quick_get_constant(
482-
const zval *key, uint32_t flags, zend_bool *is_deprecated)
483-
{
484-
zval *zv;
485-
const zval *orig_key = key;
486-
zend_constant *c = NULL;
487-
488-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
489-
if (zv) {
490-
c = (zend_constant*)Z_PTR_P(zv);
491-
} else {
492-
key++;
493-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
494-
if (zv && (((zend_constant*)Z_PTR_P(zv))->flags & CONST_CS) == 0) {
495-
c = (zend_constant*)Z_PTR_P(zv);
496-
} else {
497-
if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
498-
key++;
499-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
500-
if (zv) {
501-
c = (zend_constant*)Z_PTR_P(zv);
502-
} else {
503-
key++;
504-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
505-
if (zv && (((zend_constant*)Z_PTR_P(zv))->flags & CONST_CS) == 0) {
506-
c = (zend_constant*)Z_PTR_P(zv);
507-
}
508-
}
509-
}
510-
}
511-
}
512-
513-
if (!c) {
514-
return NULL;
515-
}
516-
517-
if (is_deprecated) {
518-
if (c->flags & (CONST_CS|CONST_CT_SUBST)) {
519-
/* Constant is case-sensitive or true/false/null */
520-
*is_deprecated = 0;
521-
} else {
522-
zend_bool ns_fallback = key >= orig_key + 2;
523-
const zval *access_key = ns_fallback ? orig_key + 2 : orig_key - 1;
524-
*is_deprecated = is_access_deprecated(c, Z_STRVAL_P(access_key));
525-
}
526-
}
527-
528-
return c;
529-
}
530-
531481
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
532482
{
533483
void *ret;

Zend/zend_constants.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ ZEND_API int zend_register_constant(zend_constant *c);
8282
#ifdef ZTS
8383
void zend_copy_constants(HashTable *target, HashTable *sourc);
8484
#endif
85-
ZEND_API zend_constant* ZEND_FASTCALL zend_quick_get_constant(
86-
const zval *key, uint32_t flags, zend_bool *is_deprecated);
8785
END_EXTERN_C()
8886

8987
#define ZEND_CONSTANT_DTOR free_zend_constant

Zend/zend_execute.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,119 @@ static zend_never_inline zend_bool ZEND_FASTCALL zend_fe_reset_iterator(zval *ar
32853285
}
32863286
/* }}} */
32873287

3288+
static zend_always_inline int _zend_quick_get_constant(
3289+
const zval *key, uint32_t flags, int check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
3290+
{
3291+
zval *zv;
3292+
const zval *orig_key = key;
3293+
zend_constant *c = NULL;
3294+
3295+
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
3296+
if (zv) {
3297+
c = (zend_constant*)Z_PTR_P(zv);
3298+
} else {
3299+
key++;
3300+
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
3301+
if (zv && (((zend_constant*)Z_PTR_P(zv))->flags & CONST_CS) == 0) {
3302+
c = (zend_constant*)Z_PTR_P(zv);
3303+
} else {
3304+
if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
3305+
key++;
3306+
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
3307+
if (zv) {
3308+
c = (zend_constant*)Z_PTR_P(zv);
3309+
} else {
3310+
key++;
3311+
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
3312+
if (zv && (((zend_constant*)Z_PTR_P(zv))->flags & CONST_CS) == 0) {
3313+
c = (zend_constant*)Z_PTR_P(zv);
3314+
}
3315+
}
3316+
}
3317+
}
3318+
}
3319+
3320+
if (!c) {
3321+
if (!check_defined_only) {
3322+
if ((opline->op1.num & IS_CONSTANT_UNQUALIFIED) != 0) {
3323+
char *actual = (char *)zend_memrchr(Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)), '\\', Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)));
3324+
if (!actual) {
3325+
ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_STR_P(RT_CONSTANT(opline, opline->op2)));
3326+
} else {
3327+
actual++;
3328+
ZVAL_STRINGL(EX_VAR(opline->result.var),
3329+
actual, Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)) - (actual - Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))));
3330+
}
3331+
/* non-qualified constant - allow text substitution */
3332+
zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)",
3333+
Z_STRVAL_P(EX_VAR(opline->result.var)), Z_STRVAL_P(EX_VAR(opline->result.var)));
3334+
} else {
3335+
zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
3336+
ZVAL_UNDEF(EX_VAR(opline->result.var));
3337+
}
3338+
}
3339+
return FAILURE;
3340+
}
3341+
3342+
if (!check_defined_only) {
3343+
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
3344+
if (!(c->flags & (CONST_CS|CONST_CT_SUBST))) {
3345+
const char *ns_sep;
3346+
size_t shortname_offset;
3347+
size_t shortname_len;
3348+
zend_bool is_deprecated;
3349+
3350+
if (flags & IS_CONSTANT_UNQUALIFIED) {
3351+
const zval *access_key;
3352+
3353+
if (!(flags & IS_CONSTANT_IN_NAMESPACE)) {
3354+
access_key = orig_key - 1;
3355+
} else {
3356+
if (key < orig_key + 2) {
3357+
goto check_short_name;
3358+
} else {
3359+
access_key = orig_key + 2;
3360+
}
3361+
}
3362+
is_deprecated = !zend_string_equals(c->name, Z_STR_P(access_key));
3363+
} else {
3364+
check_short_name:
3365+
ns_sep = zend_memrchr(ZSTR_VAL(c->name), '\\', ZSTR_LEN(c->name));
3366+
ZEND_ASSERT(ns_sep);
3367+
/* Namespaces are always case-insensitive. Only compare shortname. */
3368+
shortname_offset = ns_sep - ZSTR_VAL(c->name) + 1;
3369+
shortname_len = ZSTR_LEN(c->name) - shortname_offset;
3370+
3371+
is_deprecated = memcmp(ZSTR_VAL(c->name) + shortname_offset, Z_STRVAL_P(orig_key - 1) + shortname_offset, shortname_len) != 0;
3372+
}
3373+
3374+
if (is_deprecated) {
3375+
zend_error(E_DEPRECATED,
3376+
"Case-insensitive constants are deprecated. "
3377+
"The correct casing for this constant is \"%s\"",
3378+
ZSTR_VAL(c->name));
3379+
return SUCCESS;
3380+
}
3381+
}
3382+
}
3383+
3384+
CACHE_PTR(opline->extended_value, c);
3385+
return SUCCESS;
3386+
}
3387+
/* }}} */
3388+
3389+
static zend_never_inline void ZEND_FASTCALL zend_quick_get_constant(
3390+
const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
3391+
{
3392+
_zend_quick_get_constant(key, flags, 0 OPLINE_CC EXECUTE_DATA_CC);
3393+
}
3394+
3395+
static zend_never_inline int ZEND_FASTCALL zend_quick_check_constant(
3396+
const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
3397+
{
3398+
return _zend_quick_get_constant(key, flags, 1 OPLINE_CC EXECUTE_DATA_CC);
3399+
}
3400+
32883401
#ifdef ZEND_VM_TRACE_HANDLERS
32893402
# include "zend_vm_trace_handlers.h"
32903403
#elif defined(ZEND_VM_TRACE_MAP)

Zend/zend_vm_def.h

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,47 +5045,16 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, UNUSED|CONST_FETCH, CONST, CACHE_SLOT)
50455045
{
50465046
USE_OPLINE
50475047
zend_constant *c;
5048-
zend_bool is_deprecated;
50495048

50505049
c = CACHED_PTR(opline->extended_value);
50515050
if (EXPECTED(c != NULL) && EXPECTED(!IS_SPECIAL_CACHE_VAL(c))) {
5052-
/* pass */
5053-
} else if (UNEXPECTED((c = zend_quick_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num, &is_deprecated)) == NULL)) {
5054-
SAVE_OPLINE();
5055-
5056-
if ((opline->op1.num & IS_CONSTANT_UNQUALIFIED) != 0) {
5057-
char *actual = (char *)zend_memrchr(Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)), '\\', Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)));
5058-
if (!actual) {
5059-
ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_STR_P(RT_CONSTANT(opline, opline->op2)));
5060-
} else {
5061-
actual++;
5062-
ZVAL_STRINGL(EX_VAR(opline->result.var),
5063-
actual, Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)) - (actual - Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))));
5064-
}
5065-
/* non-qualified constant - allow text substitution */
5066-
zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)",
5067-
Z_STRVAL_P(EX_VAR(opline->result.var)), Z_STRVAL_P(EX_VAR(opline->result.var)));
5068-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
5069-
} else {
5070-
zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
5071-
ZVAL_UNDEF(EX_VAR(opline->result.var));
5072-
HANDLE_EXCEPTION();
5073-
}
5074-
} else if (is_deprecated) {
5075-
SAVE_OPLINE();
5076-
zend_error(E_DEPRECATED,
5077-
"Case-insensitive constants are deprecated. "
5078-
"The correct casing for this constant is \"%s\"",
5079-
ZSTR_VAL(c->name));
50805051
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
5081-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
5082-
} else {
5083-
CACHE_PTR(opline->extended_value, c);
5052+
ZEND_VM_NEXT_OPCODE();
50845053
}
50855054

5086-
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
5087-
5088-
ZEND_VM_NEXT_OPCODE();
5055+
SAVE_OPLINE();
5056+
zend_quick_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num OPLINE_CC EXECUTE_DATA_CC);
5057+
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
50895058
}
50905059

50915060
ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CONST, CACHE_SLOT)
@@ -7620,11 +7589,10 @@ ZEND_VM_HANDLER(122, ZEND_DEFINED, CONST, ANY, CACHE_SLOT)
76207589
break;
76217590
}
76227591
}
7623-
if ((c = zend_quick_get_constant(RT_CONSTANT(opline, opline->op1), 0, NULL)) == NULL) {
7592+
if (zend_quick_check_constant(RT_CONSTANT(opline, opline->op1), ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK OPLINE_CC EXECUTE_DATA_CC) != SUCCESS) {
76247593
CACHE_PTR(opline->extended_value, ENCODE_SPECIAL_CACHE_NUM(zend_hash_num_elements(EG(zend_constants))));
76257594
result = 0;
76267595
} else {
7627-
CACHE_PTR(opline->extended_value, c);
76287596
result = 1;
76297597
}
76307598
} while (0);

Zend/zend_vm_execute.h

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,11 +3883,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DEFINED_SPEC_CONST_HANDLER(ZEN
38833883
break;
38843884
}
38853885
}
3886-
if ((c = zend_quick_get_constant(RT_CONSTANT(opline, opline->op1), 0, NULL)) == NULL) {
3886+
if (zend_quick_check_constant(RT_CONSTANT(opline, opline->op1), ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK OPLINE_CC EXECUTE_DATA_CC) != SUCCESS) {
38873887
CACHE_PTR(opline->extended_value, ENCODE_SPECIAL_CACHE_NUM(zend_hash_num_elements(EG(zend_constants))));
38883888
result = 0;
38893889
} else {
3890-
CACHE_PTR(opline->extended_value, c);
38913890
result = 1;
38923891
}
38933892
} while (0);
@@ -31965,47 +31964,16 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_UNUSED_CON
3196531964
{
3196631965
USE_OPLINE
3196731966
zend_constant *c;
31968-
zend_bool is_deprecated;
3196931967

3197031968
c = CACHED_PTR(opline->extended_value);
3197131969
if (EXPECTED(c != NULL) && EXPECTED(!IS_SPECIAL_CACHE_VAL(c))) {
31972-
/* pass */
31973-
} else if (UNEXPECTED((c = zend_quick_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num, &is_deprecated)) == NULL)) {
31974-
SAVE_OPLINE();
31975-
31976-
if ((opline->op1.num & IS_CONSTANT_UNQUALIFIED) != 0) {
31977-
char *actual = (char *)zend_memrchr(Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)), '\\', Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)));
31978-
if (!actual) {
31979-
ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_STR_P(RT_CONSTANT(opline, opline->op2)));
31980-
} else {
31981-
actual++;
31982-
ZVAL_STRINGL(EX_VAR(opline->result.var),
31983-
actual, Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)) - (actual - Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))));
31984-
}
31985-
/* non-qualified constant - allow text substitution */
31986-
zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)",
31987-
Z_STRVAL_P(EX_VAR(opline->result.var)), Z_STRVAL_P(EX_VAR(opline->result.var)));
31988-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
31989-
} else {
31990-
zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
31991-
ZVAL_UNDEF(EX_VAR(opline->result.var));
31992-
HANDLE_EXCEPTION();
31993-
}
31994-
} else if (is_deprecated) {
31995-
SAVE_OPLINE();
31996-
zend_error(E_DEPRECATED,
31997-
"Case-insensitive constants are deprecated. "
31998-
"The correct casing for this constant is \"%s\"",
31999-
ZSTR_VAL(c->name));
3200031970
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
32001-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
32002-
} else {
32003-
CACHE_PTR(opline->extended_value, c);
31971+
ZEND_VM_NEXT_OPCODE();
3200431972
}
3200531973

32006-
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
32007-
32008-
ZEND_VM_NEXT_OPCODE();
31974+
SAVE_OPLINE();
31975+
zend_quick_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num OPLINE_CC EXECUTE_DATA_CC);
31976+
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
3200931977
}
3201031978

3201131979
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)

0 commit comments

Comments
 (0)