@@ -1759,101 +1759,79 @@ ZEND_FUNCTION(restore_exception_handler)
1759
1759
}
1760
1760
/* }}} */
1761
1761
1762
- static int copy_class_or_interface_name (zval * el , int num_args , va_list args , zend_hash_key * hash_key ) /* {{{ */
1763
- {
1764
- zend_class_entry * ce = (zend_class_entry * )Z_PTR_P (el );
1765
- zval * array = va_arg (args , zval * );
1766
- uint32_t mask = va_arg (args , uint32_t );
1767
- uint32_t comply = va_arg (args , uint32_t );
1768
- uint32_t comply_mask = (comply )? mask :0 ;
1769
-
1770
- if ((hash_key -> key && ZSTR_VAL (hash_key -> key )[0 ] != 0 )
1771
- && (comply_mask == (ce -> ce_flags & mask ))) {
1772
- if ((ce -> refcount > 1 || (ce -> ce_flags & ZEND_ACC_IMMUTABLE )) &&
1773
- !same_name (hash_key -> key , ce -> name )) {
1774
- add_next_index_str (array , zend_string_copy (hash_key -> key ));
1775
- } else {
1776
- add_next_index_str (array , zend_string_copy (ce -> name ));
1777
- }
1762
+ static void copy_class_or_interface_name (zval * array , zend_string * key , zend_class_entry * ce ) /* {{{ */
1763
+ {
1764
+ if ((ce -> refcount == 1 && !(ce -> ce_flags & ZEND_ACC_IMMUTABLE )) ||
1765
+ same_name (key , ce -> name )) {
1766
+ key = ce -> name ;
1778
1767
}
1779
- return ZEND_HASH_APPLY_KEEP ;
1768
+ add_next_index_str ( array , zend_string_copy ( key )) ;
1780
1769
}
1781
1770
/* }}} */
1782
1771
1783
1772
/* {{{ proto array get_declared_traits()
1784
1773
Returns an array of all declared traits. */
1785
1774
ZEND_FUNCTION (get_declared_traits )
1786
1775
{
1787
- uint32_t mask = ZEND_ACC_TRAIT ;
1788
- uint32_t comply = 1 ;
1776
+ zend_string * key ;
1777
+ zend_class_entry * ce ;
1789
1778
1790
1779
if (zend_parse_parameters_none () == FAILURE ) {
1791
1780
return ;
1792
1781
}
1793
1782
1794
1783
array_init (return_value );
1795
- zend_hash_apply_with_arguments (EG (class_table ), copy_class_or_interface_name , 3 , return_value , mask , comply );
1784
+ ZEND_HASH_FOREACH_STR_KEY_PTR (EG (class_table ), key , ce ) {
1785
+ if (key
1786
+ && ZSTR_VAL (key )[0 ] != 0
1787
+ && (ce -> ce_flags & ZEND_ACC_TRAIT )) {
1788
+ copy_class_or_interface_name (return_value , key , ce );
1789
+ }
1790
+ } ZEND_HASH_FOREACH_END ();
1796
1791
}
1797
1792
/* }}} */
1798
1793
1799
1794
/* {{{ proto array get_declared_classes()
1800
1795
Returns an array of all declared classes. */
1801
1796
ZEND_FUNCTION (get_declared_classes )
1802
1797
{
1803
- uint32_t mask = ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT ;
1804
- uint32_t comply = 0 ;
1798
+ zend_string * key ;
1799
+ zend_class_entry * ce ;
1805
1800
1806
1801
if (zend_parse_parameters_none () == FAILURE ) {
1807
1802
return ;
1808
1803
}
1809
1804
1810
1805
array_init (return_value );
1811
- zend_hash_apply_with_arguments (EG (class_table ), copy_class_or_interface_name , 3 , return_value , mask , comply );
1806
+ ZEND_HASH_FOREACH_STR_KEY_PTR (EG (class_table ), key , ce ) {
1807
+ if (key
1808
+ && ZSTR_VAL (key )[0 ] != 0
1809
+ && !(ce -> ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT ))) {
1810
+ copy_class_or_interface_name (return_value , key , ce );
1811
+ }
1812
+ } ZEND_HASH_FOREACH_END ();
1812
1813
}
1813
1814
/* }}} */
1814
1815
1815
1816
/* {{{ proto array get_declared_interfaces()
1816
1817
Returns an array of all declared interfaces. */
1817
1818
ZEND_FUNCTION (get_declared_interfaces )
1818
1819
{
1819
- uint32_t mask = ZEND_ACC_INTERFACE ;
1820
- uint32_t comply = 1 ;
1820
+ zend_string * key ;
1821
+ zend_class_entry * ce ;
1821
1822
1822
1823
if (zend_parse_parameters_none () == FAILURE ) {
1823
1824
return ;
1824
1825
}
1825
1826
1826
1827
array_init (return_value );
1827
- zend_hash_apply_with_arguments (EG (class_table ), copy_class_or_interface_name , 3 , return_value , mask , comply );
1828
- }
1829
- /* }}} */
1830
-
1831
- static int copy_function_name (zval * zv , int num_args , va_list args , zend_hash_key * hash_key ) /* {{{ */
1832
- {
1833
- zend_function * func = Z_PTR_P (zv );
1834
- zval * internal_ar = va_arg (args , zval * ),
1835
- * user_ar = va_arg (args , zval * );
1836
- zend_bool * exclude_disabled = va_arg (args , zend_bool * );
1837
-
1838
- if (hash_key -> key == NULL || ZSTR_VAL (hash_key -> key )[0 ] == 0 ) {
1839
- return 0 ;
1840
- }
1841
-
1842
- if (func -> type == ZEND_INTERNAL_FUNCTION ) {
1843
- char * disable_functions = INI_STR ("disable_functions" );
1844
-
1845
- if ((* exclude_disabled == 1 ) && (disable_functions != NULL )) {
1846
- if (strstr (disable_functions , func -> common .function_name -> val ) == NULL ) {
1847
- add_next_index_str (internal_ar , zend_string_copy (hash_key -> key ));
1848
- }
1849
- } else {
1850
- add_next_index_str (internal_ar , zend_string_copy (hash_key -> key ));
1828
+ ZEND_HASH_FOREACH_STR_KEY_PTR (EG (class_table ), key , ce ) {
1829
+ if (key
1830
+ && ZSTR_VAL (key )[0 ] != 0
1831
+ && (ce -> ce_flags & ZEND_ACC_INTERFACE )) {
1832
+ copy_class_or_interface_name (return_value , key , ce );
1851
1833
}
1852
- } else if (func -> type == ZEND_USER_FUNCTION ) {
1853
- add_next_index_str (user_ar , zend_string_copy (hash_key -> key ));
1854
- }
1855
-
1856
- return 0 ;
1834
+ } ZEND_HASH_FOREACH_END ();
1857
1835
}
1858
1836
/* }}} */
1859
1837
@@ -1862,7 +1840,10 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
1862
1840
ZEND_FUNCTION (get_defined_functions )
1863
1841
{
1864
1842
zval internal , user ;
1843
+ zend_string * key ;
1844
+ zend_function * func ;
1865
1845
zend_bool exclude_disabled = 0 ;
1846
+ char * disable_functions = NULL ;
1866
1847
1867
1848
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|b" , & exclude_disabled ) == FAILURE ) {
1868
1849
return ;
@@ -1872,7 +1853,24 @@ ZEND_FUNCTION(get_defined_functions)
1872
1853
array_init (& user );
1873
1854
array_init (return_value );
1874
1855
1875
- zend_hash_apply_with_arguments (EG (function_table ), copy_function_name , 3 , & internal , & user , & exclude_disabled );
1856
+ if (exclude_disabled ) {
1857
+ disable_functions = INI_STR ("disable_functions" );
1858
+ }
1859
+ ZEND_HASH_FOREACH_STR_KEY_PTR (EG (function_table ), key , func ) {
1860
+ if (key && ZSTR_VAL (key )[0 ] != 0 ) {
1861
+ if (func -> type == ZEND_INTERNAL_FUNCTION ) {
1862
+ if (disable_functions != NULL ) {
1863
+ if (strstr (disable_functions , func -> common .function_name -> val ) == NULL ) {
1864
+ add_next_index_str (& internal , zend_string_copy (key ));
1865
+ }
1866
+ } else {
1867
+ add_next_index_str (& internal , zend_string_copy (key ));
1868
+ }
1869
+ } else if (func -> type == ZEND_USER_FUNCTION ) {
1870
+ add_next_index_str (& user , zend_string_copy (key ));
1871
+ }
1872
+ }
1873
+ } ZEND_HASH_FOREACH_END ();
1876
1874
1877
1875
zend_hash_str_add_new (Z_ARRVAL_P (return_value ), "internal" , sizeof ("internal" )- 1 , & internal );
1878
1876
zend_hash_str_add_new (Z_ARRVAL_P (return_value ), "user" , sizeof ("user" )- 1 , & user );
@@ -2044,15 +2042,6 @@ ZEND_FUNCTION(get_resources)
2044
2042
}
2045
2043
/* }}} */
2046
2044
2047
- static int add_extension_info (zval * item , void * arg ) /* {{{ */
2048
- {
2049
- zval * name_array = (zval * )arg ;
2050
- zend_module_entry * module = (zend_module_entry * )Z_PTR_P (item );
2051
- add_next_index_string (name_array , module -> name );
2052
- return 0 ;
2053
- }
2054
- /* }}} */
2055
-
2056
2045
static int add_zendext_info (zend_extension * ext , void * arg ) /* {{{ */
2057
2046
{
2058
2047
zval * name_array = (zval * )arg ;
@@ -2061,23 +2050,6 @@ static int add_zendext_info(zend_extension *ext, void *arg) /* {{{ */
2061
2050
}
2062
2051
/* }}} */
2063
2052
2064
- static int add_constant_info (zval * item , void * arg ) /* {{{ */
2065
- {
2066
- zval * name_array = (zval * )arg ;
2067
- zend_constant * constant = (zend_constant * )Z_PTR_P (item );
2068
- zval const_val ;
2069
-
2070
- if (!constant -> name ) {
2071
- /* skip special constants */
2072
- return 0 ;
2073
- }
2074
-
2075
- ZVAL_COPY_OR_DUP (& const_val , & constant -> value );
2076
- zend_hash_add_new (Z_ARRVAL_P (name_array ), constant -> name , & const_val );
2077
- return 0 ;
2078
- }
2079
- /* }}} */
2080
-
2081
2053
/* {{{ proto array get_loaded_extensions([bool zend_extensions])
2082
2054
Return an array containing names of loaded extensions */
2083
2055
ZEND_FUNCTION (get_loaded_extensions )
@@ -2093,7 +2065,11 @@ ZEND_FUNCTION(get_loaded_extensions)
2093
2065
if (zendext ) {
2094
2066
zend_llist_apply_with_argument (& zend_extensions , (llist_apply_with_arg_func_t )add_zendext_info , return_value );
2095
2067
} else {
2096
- zend_hash_apply_with_argument (& module_registry , add_extension_info , return_value );
2068
+ zend_module_entry * module ;
2069
+
2070
+ ZEND_HASH_FOREACH_PTR (& module_registry , module ) {
2071
+ add_next_index_string (return_value , module -> name );
2072
+ } ZEND_HASH_FOREACH_END ();
2097
2073
}
2098
2074
}
2099
2075
/* }}} */
@@ -2155,7 +2131,17 @@ ZEND_FUNCTION(get_defined_constants)
2155
2131
efree (module_names );
2156
2132
efree (modules );
2157
2133
} else {
2158
- zend_hash_apply_with_argument (EG (zend_constants ), add_constant_info , return_value );
2134
+ zend_constant * constant ;
2135
+ zval const_val ;
2136
+
2137
+ ZEND_HASH_FOREACH_PTR (EG (zend_constants ), constant ) {
2138
+ if (!constant -> name ) {
2139
+ /* skip special constants */
2140
+ continue ;
2141
+ }
2142
+ ZVAL_COPY_OR_DUP (& const_val , & constant -> value );
2143
+ zend_hash_add_new (Z_ARRVAL_P (return_value ), constant -> name , & const_val );
2144
+ } ZEND_HASH_FOREACH_END ();
2159
2145
}
2160
2146
}
2161
2147
/* }}} */
0 commit comments