@@ -1423,6 +1423,35 @@ ZEND_API zend_result zend_unmangle_property_name_ex(const zend_string *name, con
14231423}
14241424/* }}} */
14251425
1426+ static bool array_is_const_ex (zend_array * array , uint32_t * max_checks )
1427+ {
1428+ if (zend_hash_num_elements (array ) > * max_checks ) {
1429+ return false;
1430+ }
1431+ * max_checks -= zend_hash_num_elements (array );
1432+
1433+ zval * element ;
1434+ ZEND_HASH_FOREACH_VAL (array , element ) {
1435+ if (Z_TYPE_P (element ) < IS_ARRAY ) {
1436+ continue ;
1437+ } else if (Z_TYPE_P (element ) == IS_ARRAY ) {
1438+ if (!array_is_const_ex (array , max_checks )) {
1439+ return false;
1440+ }
1441+ } else if (UNEXPECTED (Z_TYPE_P (element ) >=IS_OBJECT )) {
1442+ return false;
1443+ }
1444+ } ZEND_HASH_FOREACH_END ();
1445+
1446+ return true;
1447+ }
1448+
1449+ static bool array_is_const (zend_array * array )
1450+ {
1451+ uint32_t max_checks = 50 ;
1452+ return array_is_const_ex (array , & max_checks );
1453+ }
1454+
14261455static bool can_ct_eval_const (zend_constant * c ) {
14271456 if (ZEND_CONSTANT_FLAGS (c ) & CONST_DEPRECATED ) {
14281457 return 0 ;
@@ -1433,9 +1462,13 @@ static bool can_ct_eval_const(zend_constant *c) {
14331462 && (CG (compiler_options ) & ZEND_COMPILE_WITH_FILE_CACHE ))) {
14341463 return 1 ;
14351464 }
1436- if (Z_TYPE (c -> value ) < IS_OBJECT
1465+ if (Z_TYPE (c -> value ) < IS_ARRAY
14371466 && !(CG (compiler_options ) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION )) {
14381467 return 1 ;
1468+ } else if (Z_TYPE (c -> value ) == IS_ARRAY
1469+ && !(CG (compiler_options ) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION )
1470+ && array_is_const (Z_ARR (c -> value ))) {
1471+ return 1 ;
14391472 }
14401473 return 0 ;
14411474}
@@ -1660,7 +1693,10 @@ static bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend
16601693 c = & cc -> value ;
16611694
16621695 /* Substitute case-sensitive (or lowercase) persistent class constants */
1663- if (Z_TYPE_P (c ) < IS_OBJECT ) {
1696+ if (Z_TYPE_P (c ) < IS_ARRAY ) {
1697+ ZVAL_COPY_OR_DUP (zv , c );
1698+ return 1 ;
1699+ } else if (Z_TYPE_P (c ) == IS_ARRAY && array_is_const (Z_ARR_P (c ))) {
16641700 ZVAL_COPY_OR_DUP (zv , c );
16651701 return 1 ;
16661702 }
0 commit comments