34
34
#define RESET_CONSTANT_VISITED (zv ) Z_ACCESS_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
35
35
36
36
/* Use for special null/true/false constants. */
37
- static zval null_value , true_value , false_value ;
37
+ static zend_constant * null_const , * true_const , * false_const ;
38
38
39
39
void free_zend_constant (zval * zv )
40
40
{
@@ -138,9 +138,9 @@ void zend_register_standard_constants(void)
138
138
REGISTER_MAIN_BOOL_CONSTANT ("FALSE" , 0 , CONST_PERSISTENT );
139
139
REGISTER_MAIN_NULL_CONSTANT ("NULL" , CONST_PERSISTENT );
140
140
141
- ZVAL_NULL ( & null_value );
142
- ZVAL_TRUE ( & true_value );
143
- ZVAL_FALSE ( & false_value );
141
+ true_const = zend_hash_str_find_ptr ( EG ( zend_constants ), "TRUE" , sizeof ( "TRUE" ) - 1 );
142
+ false_const = zend_hash_str_find_ptr ( EG ( zend_constants ), "FALSE" , sizeof ( "FALSE" ) - 1 );
143
+ null_const = zend_hash_str_find_ptr ( EG ( zend_constants ), "NULL" , sizeof ( "NULL" ) - 1 );
144
144
}
145
145
146
146
@@ -235,22 +235,22 @@ static zend_constant *zend_get_halt_offset_constant(const char *name, size_t nam
235
235
}
236
236
}
237
237
238
- ZEND_API zval * _zend_get_special_const (const char * name , size_t len ) /* {{{ */
238
+ ZEND_API zend_constant * _zend_get_special_const (const char * name , size_t len ) /* {{{ */
239
239
{
240
240
if (len == 4 ) {
241
241
if ((name [0 ] == 'n' || name [0 ] == 'N' ) &&
242
242
(name [1 ] == 'u' || name [1 ] == 'U' ) &&
243
243
(name [2 ] == 'l' || name [2 ] == 'L' ) &&
244
244
(name [3 ] == 'l' || name [3 ] == 'L' )
245
245
) {
246
- return & null_value ;
246
+ return null_const ;
247
247
}
248
248
if ((name [0 ] == 't' || name [0 ] == 'T' ) &&
249
249
(name [1 ] == 'r' || name [1 ] == 'R' ) &&
250
250
(name [2 ] == 'u' || name [2 ] == 'U' ) &&
251
251
(name [3 ] == 'e' || name [3 ] == 'E' )
252
252
) {
253
- return & true_value ;
253
+ return true_const ;
254
254
}
255
255
} else {
256
256
if ((name [0 ] == 'f' || name [0 ] == 'F' ) &&
@@ -259,10 +259,10 @@ ZEND_API zval *_zend_get_special_const(const char *name, size_t len) /* {{{ */
259
259
(name [3 ] == 's' || name [3 ] == 'S' ) &&
260
260
(name [4 ] == 'e' || name [4 ] == 'E' )
261
261
) {
262
- return & false_value ;
262
+ return false_const ;
263
263
}
264
264
}
265
- return 0 ;
265
+ return NULL ;
266
266
}
267
267
/* }}} */
268
268
@@ -279,36 +279,54 @@ ZEND_API int zend_verify_const_access(zend_class_constant *c, zend_class_entry *
279
279
}
280
280
/* }}} */
281
281
282
- ZEND_API zval * zend_get_constant_str (const char * name , size_t name_len )
282
+ static zend_constant * zend_get_constant_str_impl (const char * name , size_t name_len )
283
283
{
284
284
zend_constant * c = zend_hash_str_find_ptr (EG (zend_constants ), name , name_len );
285
285
if (c ) {
286
- return & c -> value ;
286
+ return c ;
287
287
}
288
288
289
289
c = zend_get_halt_offset_constant (name , name_len );
290
290
if (c ) {
291
- return & c -> value ;
291
+ return c ;
292
292
}
293
293
294
294
return zend_get_special_const (name , name_len );
295
295
}
296
296
297
- ZEND_API zval * zend_get_constant ( zend_string * name )
297
+ ZEND_API zval * zend_get_constant_str ( const char * name , size_t name_len )
298
298
{
299
- zend_constant * c = zend_hash_find_ptr ( EG ( zend_constants ), name );
299
+ zend_constant * c = zend_get_constant_str_impl ( name , name_len );
300
300
if (c ) {
301
301
return & c -> value ;
302
302
}
303
+ return NULL ;
304
+ }
305
+
306
+ static zend_constant * zend_get_constant_impl (zend_string * name )
307
+ {
308
+ zend_constant * c = zend_hash_find_ptr (EG (zend_constants ), name );
309
+ if (c ) {
310
+ return c ;
311
+ }
303
312
304
313
c = zend_get_halt_offset_constant (ZSTR_VAL (name ), ZSTR_LEN (name ));
305
314
if (c ) {
306
- return & c -> value ;
315
+ return c ;
307
316
}
308
317
309
318
return zend_get_special_const (ZSTR_VAL (name ), ZSTR_LEN (name ));
310
319
}
311
320
321
+ ZEND_API zval * zend_get_constant (zend_string * name )
322
+ {
323
+ zend_constant * c = zend_get_constant_impl (name );
324
+ if (c ) {
325
+ return & c -> value ;
326
+ }
327
+ return NULL ;
328
+ }
329
+
312
330
ZEND_API zval * zend_get_constant_ex (zend_string * cname , zend_class_entry * scope , uint32_t flags )
313
331
{
314
332
zend_constant * c ;
@@ -402,7 +420,6 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
402
420
}
403
421
404
422
/* non-class constant */
405
- zval * value ;
406
423
if ((colon = zend_memrchr (name , '\\' , name_len )) != NULL ) {
407
424
/* compound constant name */
408
425
int prefix_len = colon - name ;
@@ -423,28 +440,28 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
423
440
c = zend_hash_str_find_ptr (EG (zend_constants ), lcname , lcname_len );
424
441
free_alloca (lcname , use_heap );
425
442
426
- if (c ) {
427
- return & c -> value ;
428
- }
429
-
430
- if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE ) {
431
- /* name requires runtime resolution, need to check non-namespaced name */
432
- value = zend_get_constant_str (constant_name , const_name_len );
433
- } else {
434
- value = NULL ;
443
+ if (!c ) {
444
+ if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE ) {
445
+ /* name requires runtime resolution, need to check non-namespaced name */
446
+ c = zend_get_constant_str_impl (constant_name , const_name_len );
447
+ }
435
448
}
436
449
} else {
437
450
if (cname ) {
438
- value = zend_get_constant (cname );
451
+ c = zend_get_constant_impl (cname );
439
452
} else {
440
- value = zend_get_constant_str (name , name_len );
453
+ c = zend_get_constant_str_impl (name , name_len );
441
454
}
442
455
}
443
456
444
- if (!value && !(flags & ZEND_FETCH_CLASS_SILENT )) {
445
- zend_throw_error (NULL , "Undefined constant '%s'" , name );
457
+ if (!(flags & ZEND_FETCH_CLASS_SILENT )) {
458
+ if (!c ) {
459
+ zend_throw_error (NULL , "Undefined constant '%s'" , name );
460
+ } else if (ZEND_CONSTANT_FLAGS (c ) & CONST_DEPRECATED ) {
461
+ zend_error (E_DEPRECATED , "Constant %s is deprecated" , name );
462
+ }
446
463
}
447
- return value ;
464
+ return & c -> value ;
448
465
}
449
466
450
467
static void * zend_hash_add_constant (HashTable * ht , zend_string * key , zend_constant * c )
0 commit comments