@@ -695,7 +695,7 @@ zend_string *zend_resolve_class_name(zend_string *name, uint32_t type) /* {{{ */
695
695
zend_string_addref (name );
696
696
}
697
697
/* Ensure that \self, \parent and \static are not used */
698
- if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type (name )) {
698
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (name )) {
699
699
zend_error_noreturn (E_COMPILE_ERROR , "'\\%s' is an invalid class name" , name -> val );
700
700
}
701
701
return name ;
@@ -1479,6 +1479,27 @@ uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */
1479
1479
}
1480
1480
/* }}} */
1481
1481
1482
+ uint32_t zend_check_reserved_name (zend_string * name ) /* {{{ */
1483
+ {
1484
+ if (zend_string_equals_literal_ci (name , "self" )) {
1485
+ return ZEND_FETCH_CLASS_SELF ;
1486
+ } else if (zend_string_equals_literal_ci (name , "parent" )) {
1487
+ return ZEND_FETCH_CLASS_PARENT ;
1488
+ } else if (zend_string_equals_literal_ci (name , "static" )) {
1489
+ return ZEND_FETCH_CLASS_STATIC ;
1490
+ } else if (zend_string_equals_literal_ci (name , "namespace" )) {
1491
+ return ZEND_FETCH_NAMESPACE ;
1492
+ } else if (zend_string_equals_literal_ci (name , "array" )) {
1493
+ return ZEND_FETCH_ARRAY ;
1494
+ } else if (zend_string_equals_literal_ci (name , "callable" )) {
1495
+ return ZEND_FETCH_CALLABLE ;
1496
+ } else {
1497
+ return ZEND_FETCH_CLASS_DEFAULT ;
1498
+ }
1499
+ }
1500
+ /* }}} */
1501
+
1502
+
1482
1503
ZEND_API zend_string * zend_get_compiled_variable_name (const zend_op_array * op_array , uint32_t var ) /* {{{ */
1483
1504
{
1484
1505
return op_array -> vars [EX_VAR_TO_NUM (var )];
@@ -4404,6 +4425,12 @@ void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
4404
4425
zend_const_expr_to_zval (& value_zv , value_ast );
4405
4426
4406
4427
name = zend_new_interned_string_safe (name );
4428
+
4429
+ if (zend_string_equals_literal_ci (name , "class" )) {
4430
+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot redefine %s::%s as ::%s is reserved" ,
4431
+ ce -> name -> val , name -> val , name -> val );
4432
+ }
4433
+
4407
4434
if (zend_hash_add (& ce -> constants_table , name , & value_zv ) == NULL ) {
4408
4435
zend_error_noreturn (E_COMPILE_ERROR , "Cannot redefine class constant %s::%s" ,
4409
4436
ce -> name -> val , name -> val );
@@ -4513,13 +4540,8 @@ void zend_compile_use_trait(zend_ast *ast) /* {{{ */
4513
4540
"%s is used in %s" , name -> val , ce -> name -> val );
4514
4541
}
4515
4542
4516
- switch (zend_get_class_fetch_type (name )) {
4517
- case ZEND_FETCH_CLASS_SELF :
4518
- case ZEND_FETCH_CLASS_PARENT :
4519
- case ZEND_FETCH_CLASS_STATIC :
4520
- zend_error_noreturn (E_COMPILE_ERROR , "Cannot use '%s' as trait name "
4521
- "as it is reserved" , name -> val );
4522
- break ;
4543
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (name )) {
4544
+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot use '%s' as trait name as it is reserved" , name -> val );
4523
4545
}
4524
4546
4525
4547
opline = get_next_op (CG (active_op_array ));
@@ -4593,7 +4615,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
4593
4615
return ;
4594
4616
}
4595
4617
4596
- if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type (name )) {
4618
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (name )) {
4597
4619
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use '%s' as class name as it is reserved" ,
4598
4620
name -> val );
4599
4621
}
@@ -4845,13 +4867,16 @@ void zend_compile_use(zend_ast *ast) /* {{{ */
4845
4867
lookup_name = zend_string_tolower (new_name );
4846
4868
}
4847
4869
4848
- if (type == T_CLASS && (zend_string_equals_literal (lookup_name , "self" )
4849
- || zend_string_equals_literal (lookup_name , "parent" ))
4850
- ) {
4870
+ if (type == T_CLASS && ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (lookup_name )) {
4851
4871
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use %s as %s because '%s' "
4852
4872
"is a special class name" , old_name -> val , new_name -> val , new_name -> val );
4853
4873
}
4854
4874
4875
+ if (type == T_CLASS && ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (old_name )) {
4876
+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot use %s because '%s' "
4877
+ "is a special class name" , old_name -> val , old_name -> val );
4878
+ }
4879
+
4855
4880
if (current_ns ) {
4856
4881
zend_string * ns_name = zend_string_alloc (current_ns -> len + 1 + new_name -> len , 0 );
4857
4882
zend_str_tolower_copy (ns_name -> val , current_ns -> val , current_ns -> len );
@@ -5001,7 +5026,7 @@ void zend_compile_namespace(zend_ast *ast) /* {{{ */
5001
5026
if (name_ast ) {
5002
5027
name = zend_ast_get_str (name_ast );
5003
5028
5004
- if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type (name )) {
5029
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_check_reserved_name (name )) {
5005
5030
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use '%s' as namespace name" , name -> val );
5006
5031
}
5007
5032
@@ -5842,7 +5867,7 @@ void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */
5842
5867
zend_ast * const_ast = ast -> child [1 ];
5843
5868
5844
5869
znode class_node , const_node ;
5845
- zend_op * opline , * class_op = NULL ;
5870
+ zend_op * opline ;
5846
5871
zend_string * resolved_name ;
5847
5872
5848
5873
zend_eval_const_expr (& class_ast );
@@ -5864,7 +5889,7 @@ void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */
5864
5889
if (class_ast -> kind == ZEND_AST_ZVAL ) {
5865
5890
zend_string_release (resolved_name );
5866
5891
}
5867
- class_op = zend_compile_class_ref (& class_node , class_ast );
5892
+ zend_compile_class_ref (& class_node , class_ast );
5868
5893
}
5869
5894
5870
5895
zend_compile_expr (& const_node , const_ast );
0 commit comments