PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_builtin_functions.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 995 1090 91.3 %
Date: 2015-01-18 Functions: 67 67 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include "zend_API.h"
      24             : #include "zend_builtin_functions.h"
      25             : #include "zend_constants.h"
      26             : #include "zend_ini.h"
      27             : #include "zend_exceptions.h"
      28             : #include "zend_extensions.h"
      29             : #include "zend_closures.h"
      30             : 
      31             : #undef ZEND_TEST_EXCEPTIONS
      32             : 
      33             : static ZEND_FUNCTION(zend_version);
      34             : static ZEND_FUNCTION(func_num_args);
      35             : static ZEND_FUNCTION(func_get_arg);
      36             : static ZEND_FUNCTION(func_get_args);
      37             : static ZEND_FUNCTION(strlen);
      38             : static ZEND_FUNCTION(strcmp);
      39             : static ZEND_FUNCTION(strncmp);
      40             : static ZEND_FUNCTION(strcasecmp);
      41             : static ZEND_FUNCTION(strncasecmp);
      42             : static ZEND_FUNCTION(each);
      43             : static ZEND_FUNCTION(error_reporting);
      44             : static ZEND_FUNCTION(define);
      45             : static ZEND_FUNCTION(defined);
      46             : static ZEND_FUNCTION(get_class);
      47             : static ZEND_FUNCTION(get_called_class);
      48             : static ZEND_FUNCTION(get_parent_class);
      49             : static ZEND_FUNCTION(method_exists);
      50             : static ZEND_FUNCTION(property_exists);
      51             : static ZEND_FUNCTION(class_exists);
      52             : static ZEND_FUNCTION(interface_exists);
      53             : static ZEND_FUNCTION(trait_exists);
      54             : static ZEND_FUNCTION(function_exists);
      55             : static ZEND_FUNCTION(class_alias);
      56             : #if ZEND_DEBUG
      57             : static ZEND_FUNCTION(leak);
      58             : static ZEND_FUNCTION(leak_variable);
      59             : #ifdef ZEND_TEST_EXCEPTIONS
      60             : static ZEND_FUNCTION(crash);
      61             : #endif
      62             : #endif
      63             : static ZEND_FUNCTION(get_included_files);
      64             : static ZEND_FUNCTION(is_subclass_of);
      65             : static ZEND_FUNCTION(is_a);
      66             : static ZEND_FUNCTION(get_class_vars);
      67             : static ZEND_FUNCTION(get_object_vars);
      68             : static ZEND_FUNCTION(get_class_methods);
      69             : static ZEND_FUNCTION(trigger_error);
      70             : static ZEND_FUNCTION(set_error_handler);
      71             : static ZEND_FUNCTION(restore_error_handler);
      72             : static ZEND_FUNCTION(set_exception_handler);
      73             : static ZEND_FUNCTION(restore_exception_handler);
      74             : static ZEND_FUNCTION(get_declared_classes);
      75             : static ZEND_FUNCTION(get_declared_traits);
      76             : static ZEND_FUNCTION(get_declared_interfaces);
      77             : static ZEND_FUNCTION(get_defined_functions);
      78             : static ZEND_FUNCTION(get_defined_vars);
      79             : static ZEND_FUNCTION(create_function);
      80             : static ZEND_FUNCTION(get_resource_type);
      81             : static ZEND_FUNCTION(get_resources);
      82             : static ZEND_FUNCTION(get_loaded_extensions);
      83             : static ZEND_FUNCTION(extension_loaded);
      84             : static ZEND_FUNCTION(get_extension_funcs);
      85             : static ZEND_FUNCTION(get_defined_constants);
      86             : static ZEND_FUNCTION(debug_backtrace);
      87             : static ZEND_FUNCTION(debug_print_backtrace);
      88             : #if ZEND_DEBUG
      89             : static ZEND_FUNCTION(zend_test_func);
      90             : #ifdef ZTS
      91             : static ZEND_FUNCTION(zend_thread_id);
      92             : #endif
      93             : #endif
      94             : static ZEND_FUNCTION(gc_collect_cycles);
      95             : static ZEND_FUNCTION(gc_enabled);
      96             : static ZEND_FUNCTION(gc_enable);
      97             : static ZEND_FUNCTION(gc_disable);
      98             : 
      99             : /* {{{ arginfo */
     100             : ZEND_BEGIN_ARG_INFO(arginfo_zend__void, 0)
     101             : ZEND_END_ARG_INFO()
     102             : 
     103             : ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
     104             :         ZEND_ARG_INFO(0, arg_num)
     105             : ZEND_END_ARG_INFO()
     106             : 
     107             : ZEND_BEGIN_ARG_INFO_EX(arginfo_strlen, 0, 0, 1)
     108             :         ZEND_ARG_INFO(0, str)
     109             : ZEND_END_ARG_INFO()
     110             : 
     111             : ZEND_BEGIN_ARG_INFO_EX(arginfo_strcmp, 0, 0, 2)
     112             :         ZEND_ARG_INFO(0, str1)
     113             :         ZEND_ARG_INFO(0, str2)
     114             : ZEND_END_ARG_INFO()
     115             : 
     116             : ZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3)
     117             :         ZEND_ARG_INFO(0, str1)
     118             :         ZEND_ARG_INFO(0, str2)
     119             :         ZEND_ARG_INFO(0, len)
     120             : ZEND_END_ARG_INFO()
     121             : 
     122             : ZEND_BEGIN_ARG_INFO_EX(arginfo_each, 0, 0, 1)
     123             :         ZEND_ARG_INFO(1, arr)
     124             : ZEND_END_ARG_INFO()
     125             : 
     126             : ZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0)
     127             :         ZEND_ARG_INFO(0, new_error_level)
     128             : ZEND_END_ARG_INFO()
     129             : 
     130             : ZEND_BEGIN_ARG_INFO_EX(arginfo_define, 0, 0, 3)
     131             :         ZEND_ARG_INFO(0, constant_name)
     132             :         ZEND_ARG_INFO(0, value)
     133             :         ZEND_ARG_INFO(0, case_insensitive)
     134             : ZEND_END_ARG_INFO()
     135             : 
     136             : ZEND_BEGIN_ARG_INFO_EX(arginfo_defined, 0, 0, 1)
     137             :         ZEND_ARG_INFO(0, constant_name)
     138             : ZEND_END_ARG_INFO()
     139             : 
     140             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class, 0, 0, 0)
     141             :         ZEND_ARG_INFO(0, object)
     142             : ZEND_END_ARG_INFO()
     143             : 
     144             : ZEND_BEGIN_ARG_INFO_EX(arginfo_is_subclass_of, 0, 0, 2)
     145             :         ZEND_ARG_INFO(0, object)
     146             :         ZEND_ARG_INFO(0, class_name)
     147             :         ZEND_ARG_INFO(0, allow_string)
     148             : ZEND_END_ARG_INFO()
     149             : 
     150             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_vars, 0, 0, 1)
     151             :         ZEND_ARG_INFO(0, class_name)
     152             : ZEND_END_ARG_INFO()
     153             : 
     154             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_object_vars, 0, 0, 1)
     155             :         ZEND_ARG_INFO(0, obj)
     156             : ZEND_END_ARG_INFO()
     157             : 
     158             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1)
     159             :         ZEND_ARG_INFO(0, class)
     160             : ZEND_END_ARG_INFO()
     161             : 
     162             : ZEND_BEGIN_ARG_INFO_EX(arginfo_method_exists, 0, 0, 2)
     163             :         ZEND_ARG_INFO(0, object)
     164             :         ZEND_ARG_INFO(0, method)
     165             : ZEND_END_ARG_INFO()
     166             : 
     167             : ZEND_BEGIN_ARG_INFO_EX(arginfo_property_exists, 0, 0, 2)
     168             :         ZEND_ARG_INFO(0, object_or_class)
     169             :         ZEND_ARG_INFO(0, property_name)
     170             : ZEND_END_ARG_INFO()
     171             : 
     172             : ZEND_BEGIN_ARG_INFO_EX(arginfo_class_exists, 0, 0, 1)
     173             :         ZEND_ARG_INFO(0, classname)
     174             :         ZEND_ARG_INFO(0, autoload)
     175             : ZEND_END_ARG_INFO()
     176             : 
     177             : ZEND_BEGIN_ARG_INFO_EX(arginfo_trait_exists, 0, 0, 1)
     178             :         ZEND_ARG_INFO(0, traitname)
     179             :         ZEND_ARG_INFO(0, autoload)
     180             : ZEND_END_ARG_INFO()
     181             : 
     182             : ZEND_BEGIN_ARG_INFO_EX(arginfo_function_exists, 0, 0, 1)
     183             :         ZEND_ARG_INFO(0, function_name)
     184             : ZEND_END_ARG_INFO()
     185             : 
     186             : ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
     187             :         ZEND_ARG_INFO(0, user_class_name)
     188             :         ZEND_ARG_INFO(0, alias_name)
     189             :         ZEND_ARG_INFO(0, autoload)
     190             : ZEND_END_ARG_INFO()
     191             : 
     192             : #if ZEND_DEBUG
     193             : ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
     194             :         ZEND_ARG_INFO(0, variable)
     195             :         ZEND_ARG_INFO(0, leak_data)
     196             : ZEND_END_ARG_INFO()
     197             : #endif
     198             : 
     199             : ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
     200             :         ZEND_ARG_INFO(0, message)
     201             :         ZEND_ARG_INFO(0, error_type)
     202             : ZEND_END_ARG_INFO()
     203             : 
     204             : ZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1)
     205             :         ZEND_ARG_INFO(0, error_handler)
     206             :         ZEND_ARG_INFO(0, error_types)
     207             : ZEND_END_ARG_INFO()
     208             : 
     209             : ZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1)
     210             :         ZEND_ARG_INFO(0, exception_handler)
     211             : ZEND_END_ARG_INFO()
     212             : 
     213             : ZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2)
     214             :         ZEND_ARG_INFO(0, args)
     215             :         ZEND_ARG_INFO(0, code)
     216             : ZEND_END_ARG_INFO()
     217             : 
     218             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1)
     219             :         ZEND_ARG_INFO(0, res)
     220             : ZEND_END_ARG_INFO()
     221             : 
     222             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resources, 0, 0, 0)
     223             :         ZEND_ARG_INFO(0, type)
     224             : ZEND_END_ARG_INFO()
     225             : 
     226             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_loaded_extensions, 0, 0, 0)
     227             :         ZEND_ARG_INFO(0, zend_extensions)
     228             : ZEND_END_ARG_INFO()
     229             : 
     230             : ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_constants, 0, 0, 0)
     231             :         ZEND_ARG_INFO(0, categorize)
     232             : ZEND_END_ARG_INFO()
     233             : 
     234             : ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_backtrace, 0, 0, 0)
     235             :         ZEND_ARG_INFO(0, options)
     236             :         ZEND_ARG_INFO(0, limit)
     237             : ZEND_END_ARG_INFO()
     238             : 
     239             : ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_print_backtrace, 0, 0, 0)
     240             :         ZEND_ARG_INFO(0, options)
     241             : ZEND_END_ARG_INFO()
     242             : 
     243             : ZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1)
     244             :         ZEND_ARG_INFO(0, extension_name)
     245             : ZEND_END_ARG_INFO()
     246             : /* }}} */
     247             : 
     248             : static const zend_function_entry builtin_functions[] = { /* {{{ */
     249             :         ZEND_FE(zend_version,           arginfo_zend__void)
     250             :         ZEND_FE(func_num_args,          arginfo_zend__void)
     251             :         ZEND_FE(func_get_arg,           arginfo_func_get_arg)
     252             :         ZEND_FE(func_get_args,          arginfo_zend__void)
     253             :         ZEND_FE(strlen,                 arginfo_strlen)
     254             :         ZEND_FE(strcmp,                 arginfo_strcmp)
     255             :         ZEND_FE(strncmp,                arginfo_strncmp)
     256             :         ZEND_FE(strcasecmp,             arginfo_strcmp)
     257             :         ZEND_FE(strncasecmp,            arginfo_strncmp)
     258             :         ZEND_FE(each,                   arginfo_each)
     259             :         ZEND_FE(error_reporting,        arginfo_error_reporting)
     260             :         ZEND_FE(define,                 arginfo_define)
     261             :         ZEND_FE(defined,                arginfo_defined)
     262             :         ZEND_FE(get_class,              arginfo_get_class)
     263             :         ZEND_FE(get_called_class,       arginfo_zend__void)
     264             :         ZEND_FE(get_parent_class,       arginfo_get_class)
     265             :         ZEND_FE(method_exists,          arginfo_method_exists)
     266             :         ZEND_FE(property_exists,        arginfo_property_exists)
     267             :         ZEND_FE(class_exists,           arginfo_class_exists)
     268             :         ZEND_FE(interface_exists,       arginfo_class_exists)
     269             :         ZEND_FE(trait_exists,           arginfo_trait_exists)
     270             :         ZEND_FE(function_exists,        arginfo_function_exists)
     271             :         ZEND_FE(class_alias,            arginfo_class_alias)
     272             : #if ZEND_DEBUG
     273             :         ZEND_FE(leak,                           NULL)
     274             :         ZEND_FE(leak_variable,          arginfo_leak_variable)
     275             : #ifdef ZEND_TEST_EXCEPTIONS
     276             :         ZEND_FE(crash,                          NULL)
     277             : #endif
     278             : #endif
     279             :         ZEND_FE(get_included_files,     arginfo_zend__void)
     280             :         ZEND_FALIAS(get_required_files, get_included_files,             arginfo_zend__void)
     281             :         ZEND_FE(is_subclass_of,         arginfo_is_subclass_of)
     282             :         ZEND_FE(is_a,                   arginfo_is_subclass_of)
     283             :         ZEND_FE(get_class_vars,         arginfo_get_class_vars)
     284             :         ZEND_FE(get_object_vars,        arginfo_get_object_vars)
     285             :         ZEND_FE(get_class_methods,      arginfo_get_class_methods)
     286             :         ZEND_FE(trigger_error,          arginfo_trigger_error)
     287             :         ZEND_FALIAS(user_error,         trigger_error,          arginfo_trigger_error)
     288             :         ZEND_FE(set_error_handler,              arginfo_set_error_handler)
     289             :         ZEND_FE(restore_error_handler,          arginfo_zend__void)
     290             :         ZEND_FE(set_exception_handler,          arginfo_set_exception_handler)
     291             :         ZEND_FE(restore_exception_handler,      arginfo_zend__void)
     292             :         ZEND_FE(get_declared_classes,           arginfo_zend__void)
     293             :         ZEND_FE(get_declared_traits,            arginfo_zend__void)
     294             :         ZEND_FE(get_declared_interfaces,        arginfo_zend__void)
     295             :         ZEND_FE(get_defined_functions,          arginfo_zend__void)
     296             :         ZEND_FE(get_defined_vars,               arginfo_zend__void)
     297             :         ZEND_FE(create_function,                arginfo_create_function)
     298             :         ZEND_FE(get_resource_type,              arginfo_get_resource_type)
     299             :         ZEND_FE(get_resources,                  arginfo_get_resources)
     300             :         ZEND_FE(get_loaded_extensions,          arginfo_get_loaded_extensions)
     301             :         ZEND_FE(extension_loaded,               arginfo_extension_loaded)
     302             :         ZEND_FE(get_extension_funcs,            arginfo_extension_loaded)
     303             :         ZEND_FE(get_defined_constants,          arginfo_get_defined_constants)
     304             :         ZEND_FE(debug_backtrace,                arginfo_debug_backtrace)
     305             :         ZEND_FE(debug_print_backtrace,          arginfo_debug_print_backtrace)
     306             : #if ZEND_DEBUG
     307             :         ZEND_FE(zend_test_func,         NULL)
     308             : #ifdef ZTS
     309             :         ZEND_FE(zend_thread_id,         NULL)
     310             : #endif
     311             : #endif
     312             :         ZEND_FE(gc_collect_cycles,      arginfo_zend__void)
     313             :         ZEND_FE(gc_enabled,             arginfo_zend__void)
     314             :         ZEND_FE(gc_enable,              arginfo_zend__void)
     315             :         ZEND_FE(gc_disable,             arginfo_zend__void)
     316             :         ZEND_FE_END
     317             : };
     318             : /* }}} */
     319             : 
     320       20688 : ZEND_MINIT_FUNCTION(core) { /* {{{ */
     321             :         zend_class_entry class_entry;
     322             : 
     323       20688 :         INIT_CLASS_ENTRY(class_entry, "stdClass", NULL);
     324       20688 :         zend_standard_class_def = zend_register_internal_class(&class_entry);
     325             : 
     326       20688 :         zend_register_default_classes();
     327             : 
     328       20688 :         return SUCCESS;
     329             : }
     330             : /* }}} */
     331             : 
     332             : zend_module_entry zend_builtin_module = { /* {{{ */
     333             :     STANDARD_MODULE_HEADER,
     334             :         "Core",
     335             :         builtin_functions,
     336             :         ZEND_MINIT(core),
     337             :         NULL,
     338             :         NULL,
     339             :         NULL,
     340             :         NULL,
     341             :         ZEND_VERSION,
     342             :         STANDARD_MODULE_PROPERTIES
     343             : };
     344             : /* }}} */
     345             : 
     346       20688 : int zend_startup_builtin_functions(void) /* {{{ */
     347             : {
     348       20688 :         zend_builtin_module.module_number = 0;
     349       20688 :         zend_builtin_module.type = MODULE_PERSISTENT;
     350       20688 :         return (EG(current_module) = zend_register_module_ex(&zend_builtin_module)) == NULL ? FAILURE : SUCCESS;
     351             : }
     352             : /* }}} */
     353             : 
     354             : /* {{{ proto string zend_version(void)
     355             :    Get the version of the Zend Engine */
     356         143 : ZEND_FUNCTION(zend_version)
     357             : {
     358         286 :         RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1);
     359             : }
     360             : /* }}} */
     361             : 
     362             : /* {{{ proto int gc_collect_cycles(void)
     363             :    Forces collection of any existing garbage cycles.
     364             :    Returns number of freed zvals */
     365          47 : ZEND_FUNCTION(gc_collect_cycles)
     366             : {
     367          47 :         RETURN_LONG(gc_collect_cycles());
     368             : }
     369             : /* }}} */
     370             : 
     371             : /* {{{ proto void gc_enabled(void)
     372             :    Returns status of the circular reference collector */
     373           6 : ZEND_FUNCTION(gc_enabled)
     374             : {
     375           6 :         RETURN_BOOL(GC_G(gc_enabled));
     376             : }
     377             : /* }}} */
     378             : 
     379             : /* {{{ proto void gc_enable(void)
     380             :    Activates the circular reference collector */
     381           6 : ZEND_FUNCTION(gc_enable)
     382             : {
     383           6 :         zend_string *key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
     384           6 :         zend_alter_ini_entry_chars(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
     385             :         zend_string_release(key);
     386           6 : }
     387             : /* }}} */
     388             : 
     389             : /* {{{ proto void gc_disable(void)
     390             :    Deactivates the circular reference collector */
     391           3 : ZEND_FUNCTION(gc_disable)
     392             : {
     393           3 :         zend_string *key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
     394           3 :         zend_alter_ini_entry_chars(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
     395             :         zend_string_release(key);
     396           3 : }
     397             : /* }}} */
     398             : 
     399             : /* {{{ proto int func_num_args(void)
     400             :    Get the number of arguments that were passed to the function */
     401          16 : ZEND_FUNCTION(func_num_args)
     402             : {
     403          16 :         zend_execute_data *ex = EX(prev_execute_data);
     404             : 
     405          16 :         if (!(ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
     406          14 :                 RETURN_LONG(ZEND_CALL_NUM_ARGS(ex));
     407             :         } else {
     408           2 :                 zend_error(E_WARNING, "func_num_args():  Called from the global scope - no function context");
     409           2 :                 RETURN_LONG(-1);
     410             :         }
     411             : }
     412             : /* }}} */
     413             : 
     414             : /* {{{ proto mixed func_get_arg(int arg_num)
     415             :    Get the $arg_num'th argument that was passed to the function */
     416          42 : ZEND_FUNCTION(func_get_arg)
     417             : {
     418             :         uint32_t arg_count, first_extra_arg;
     419             :         zval *arg;
     420             :         zend_long requested_offset;
     421             :         zend_execute_data *ex;
     422             : 
     423          42 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) == FAILURE) {
     424           5 :                 return;
     425             :         }
     426             : 
     427          37 :         if (requested_offset < 0) {
     428           4 :                 zend_error(E_WARNING, "func_get_arg():  The argument number should be >= 0");
     429           4 :                 RETURN_FALSE;
     430             :         }
     431             : 
     432          33 :         ex = EX(prev_execute_data);
     433          33 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
     434           3 :                 zend_error(E_WARNING, "func_get_arg():  Called from the global scope - no function context");
     435           3 :                 RETURN_FALSE;
     436             :         }
     437             : 
     438          30 :         arg_count = ZEND_CALL_NUM_ARGS(ex);
     439             : 
     440          30 :         if (requested_offset >= arg_count) {
     441          16 :                 zend_error(E_WARNING, "func_get_arg():  Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
     442          16 :                 RETURN_FALSE;
     443             :         }
     444             : 
     445          14 :         first_extra_arg = ex->func->op_array.num_args;
     446          19 :         if (requested_offset >= first_extra_arg && (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) {
     447           5 :                 arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T) + (requested_offset - first_extra_arg);
     448             :         } else {
     449           9 :                 arg = ZEND_CALL_ARG(ex, requested_offset + 1);
     450             :         }
     451          42 :         RETURN_ZVAL_FAST(arg);
     452             : }
     453             : /* }}} */
     454             : 
     455             : /* {{{ proto array func_get_args()
     456             :    Get an array of the arguments that were passed to the function */
     457          81 : ZEND_FUNCTION(func_get_args)
     458             : {
     459             :         zval *p, *q;
     460             :         uint32_t arg_count, first_extra_arg;
     461             :         uint32_t i;
     462          81 :         zend_execute_data *ex = EX(prev_execute_data);
     463             : 
     464          81 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
     465           2 :                 zend_error(E_WARNING, "func_get_args():  Called from the global scope - no function context");
     466           2 :                 RETURN_FALSE;
     467             :         }
     468             : 
     469          79 :         arg_count = ZEND_CALL_NUM_ARGS(ex);
     470             : 
     471          79 :         array_init_size(return_value, arg_count);
     472          79 :         if (arg_count) {
     473          57 :                 first_extra_arg = ex->func->op_array.num_args;
     474          57 :                 zend_hash_real_init(Z_ARRVAL_P(return_value), 1);
     475          57 :                 ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
     476          57 :                         i = 0;
     477          57 :                         p = ZEND_CALL_ARG(ex, 1);
     478          57 :                         if (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg) {
     479          72 :                                 while (i < first_extra_arg) {
     480           2 :                                         q = p;
     481           2 :                                         ZVAL_DEREF(q);
     482           2 :                                         if (Z_OPT_REFCOUNTED_P(q)) Z_ADDREF_P(q);
     483           2 :                                         ZEND_HASH_FILL_ADD(q);
     484             : //                                      q->h = i;
     485             : //                                      q->key = NULL;
     486             : //                                      if (!Z_ISREF_P(p)) {
     487             : //                                              ZVAL_COPY(&q->val, p);
     488             : //                                      } else {
     489             : //                                              ZVAL_COPY(&q->val, Z_REFVAL_P(p));
     490             : //                                  }
     491           2 :                                         p++;
     492             : //                                      q++;
     493           2 :                                         i++;
     494             :                                 }
     495          35 :                                 p = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T);
     496             :                         }
     497         197 :                         while (i < arg_count) {
     498          83 :                                 q = p;
     499          83 :                                 ZVAL_DEREF(q);
     500          83 :                                 if (Z_OPT_REFCOUNTED_P(q)) Z_ADDREF_P(q);
     501          83 :                                 ZEND_HASH_FILL_ADD(q);
     502             : //                              q->h = i;
     503             : //                              q->key = NULL;
     504             : //                              if (!Z_ISREF_P(p)) {
     505             : //                                      ZVAL_COPY(&q->val, p);
     506             : //                              } else {
     507             : //                                      ZVAL_COPY(&q->val, Z_REFVAL_P(p));
     508             : //                          }
     509          83 :                                 p++;
     510             : //                              q++;
     511          83 :                                 i++;
     512             :                         }
     513          57 :                 } ZEND_HASH_FILL_END();
     514             :         }
     515             : }
     516             : /* }}} */
     517             : 
     518             : /* {{{ proto int strlen(string str)
     519             :    Get string length
     520             :    Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
     521         171 : ZEND_FUNCTION(strlen)
     522             : {
     523             :         zend_string *s;
     524             : 
     525             : #ifndef FAST_ZPP
     526             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &s) == FAILURE) {
     527             :                 return;
     528             :         }
     529             : #else
     530         171 :         ZEND_PARSE_PARAMETERS_START(1, 1)
     531         498 :                 Z_PARAM_STR(s)
     532         171 :         ZEND_PARSE_PARAMETERS_END();
     533             : #endif
     534             : 
     535         164 :         RETVAL_LONG(s->len);
     536             : }
     537             : /* }}} */
     538             : 
     539             : /* {{{ proto int strcmp(string str1, string str2)
     540             :    Binary safe string comparison */
     541      278114 : ZEND_FUNCTION(strcmp)
     542             : {
     543             :         zend_string *s1, *s2;
     544             : 
     545      278114 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) {
     546           5 :                 return;
     547             :         }
     548             : 
     549      278109 :         RETURN_LONG(zend_binary_strcmp(s1->val, s1->len, s2->val, s2->len));
     550             : }
     551             : /* }}} */
     552             : 
     553             : /* {{{ proto int strncmp(string str1, string str2, int len)
     554             :    Binary safe string comparison */
     555       14336 : ZEND_FUNCTION(strncmp)
     556             : {
     557             :         zend_string *s1, *s2;
     558             :         zend_long len;
     559             : 
     560       14336 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl", &s1, &s2, &len) == FAILURE) {
     561          20 :                 return;
     562             :         }
     563             : 
     564       14316 :         if (len < 0) {
     565           3 :                 zend_error(E_WARNING, "Length must be greater than or equal to 0");
     566           3 :                 RETURN_FALSE;
     567             :         }
     568             : 
     569       14313 :         RETURN_LONG(zend_binary_strncmp(s1->val, s1->len, s2->val, s2->len, len));
     570             : }
     571             : /* }}} */
     572             : 
     573             : /* {{{ proto int strcasecmp(string str1, string str2)
     574             :    Binary safe case-insensitive string comparison */
     575         755 : ZEND_FUNCTION(strcasecmp)
     576             : {
     577             :         zend_string *s1, *s2;
     578             : 
     579         755 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) {
     580           6 :                 return;
     581             :         }
     582             : 
     583         749 :         RETURN_LONG(zend_binary_strcasecmp(s1->val, s1->len, s2->val, s2->len));
     584             : }
     585             : /* }}} */
     586             : 
     587             : /* {{{ proto int strncasecmp(string str1, string str2, int len)
     588             :    Binary safe string comparison */
     589       20154 : ZEND_FUNCTION(strncasecmp)
     590             : {
     591             :         zend_string *s1, *s2;
     592             :         zend_long len;
     593             : 
     594       20154 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl", &s1, &s2, &len) == FAILURE) {
     595          32 :                 return;
     596             :         }
     597             : 
     598       20122 :         if (len < 0) {
     599           3 :                 zend_error(E_WARNING, "Length must be greater than or equal to 0");
     600           3 :                 RETURN_FALSE;
     601             :         }
     602             : 
     603       20119 :         RETURN_LONG(zend_binary_strncasecmp(s1->val, s1->len, s2->val, s2->len, len));
     604             : }
     605             : /* }}} */
     606             : 
     607             : /* {{{ proto array each(array arr)
     608             :    Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element */
     609        1464 : ZEND_FUNCTION(each)
     610             : {
     611             :         zval *array, *entry, tmp;
     612             :         zend_ulong num_key;
     613             :         HashTable *target_hash;
     614             :         zend_string *key;
     615             : 
     616        1464 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &array) == FAILURE) {
     617           5 :                 return;
     618             :         }
     619             : 
     620        2953 :         target_hash = HASH_OF(array);
     621        1459 :         if (!target_hash) {
     622          29 :                 zend_error(E_WARNING,"Variable passed to each() is not an array or object");
     623          29 :                 return;
     624             :         }
     625             :         while (1) {
     626        1430 :                 entry = zend_hash_get_current_data(target_hash);
     627        1430 :                 if (!entry) {
     628          59 :                         RETURN_FALSE;
     629        1371 :                 } else if (Z_TYPE_P(entry) == IS_INDIRECT) {
     630           3 :                         entry = Z_INDIRECT_P(entry);
     631           3 :                         if (Z_TYPE_P(entry) == IS_UNDEF) {
     632           0 :                                 zend_hash_move_forward(target_hash);
     633           0 :                                 continue;
     634             :                         }
     635             :                 }
     636        1371 :                 break;
     637           0 :         }
     638        1371 :         array_init_size(return_value, 4);
     639        1371 :         zend_hash_real_init(Z_ARRVAL_P(return_value), 0);
     640             : 
     641             :         /* add value elements */
     642        1371 :         if (Z_ISREF_P(entry)) {
     643           3 :                 ZVAL_DUP(&tmp, Z_REFVAL_P(entry));
     644           3 :                 entry = &tmp;
     645           3 :                 if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
     646             :         } else {
     647        1368 :                 if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
     648        1368 :                 if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
     649             :         }
     650        1371 :         zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
     651        1371 :         zend_hash_str_add_new(Z_ARRVAL_P(return_value), "value", sizeof("value")-1, entry);
     652             : 
     653             :         /* add the key elements */
     654        1371 :         if (zend_hash_get_current_key(target_hash, &key, &num_key) == HASH_KEY_IS_STRING) {
     655          43 :                 ZVAL_STR_COPY(&tmp, key);
     656          43 :                 if (Z_REFCOUNTED(tmp)) Z_ADDREF(tmp);
     657             :         } else {
     658        1328 :                 ZVAL_LONG(&tmp, num_key);
     659             :         }
     660        1371 :         zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
     661        1371 :         zend_hash_str_add_new(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, &tmp);
     662        1371 :         zend_hash_move_forward(target_hash);
     663             : }
     664             : /* }}} */
     665             : 
     666             : /* {{{ proto int error_reporting([int new_error_level])
     667             :    Return the current error_reporting level, and if an argument was passed - change to the new level */
     668        2395 : ZEND_FUNCTION(error_reporting)
     669             : {
     670             :         zval *err;
     671             :         int old_error_reporting;
     672             : 
     673             : #ifndef FAST_ZPP
     674             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &err) == FAILURE) {
     675             :                 return;
     676             :         }
     677             : #else
     678        2395 :         ZEND_PARSE_PARAMETERS_START(0, 1)
     679        2395 :                 Z_PARAM_OPTIONAL
     680        2395 :                 Z_PARAM_ZVAL(err)
     681        2395 :         ZEND_PARSE_PARAMETERS_END();
     682             : #endif
     683             : 
     684        2395 :         old_error_reporting = EG(error_reporting);
     685        2395 :         if(ZEND_NUM_ARGS() != 0) {
     686             :                 do {
     687         380 :                         zend_ini_entry *p = EG(error_reporting_ini_entry);
     688             : 
     689         380 :                         if (!p) {
     690         624 :                                 p = zend_hash_str_find_ptr(EG(ini_directives), "error_reporting", sizeof("error_reporting")-1);
     691         312 :                                 if (p) {
     692         312 :                                         EG(error_reporting_ini_entry) = p;
     693             :                                 } else {
     694           0 :                                         break;
     695             :                                 }
     696             :                         }
     697         380 :                         if (!p->modified) {
     698         312 :                                 if (!EG(modified_ini_directives)) {
     699         308 :                                         ALLOC_HASHTABLE(EG(modified_ini_directives));
     700         308 :                                         zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
     701             :                                 }
     702         624 :                                 if (EXPECTED(zend_hash_str_add_ptr(EG(modified_ini_directives), "error_reporting", sizeof("error_reporting")-1, p) != NULL)) {
     703         312 :                                         p->orig_value = p->value;
     704         312 :                                         p->orig_modifiable = p->modifiable;
     705         312 :                                         p->modified = 1;
     706             :                                 }
     707          68 :                         } else if (p->orig_value != p->value) {
     708          67 :                                 zend_string_release(p->value);
     709             :                         }
     710             : 
     711         760 :                         p->value = zval_get_string(err);
     712         760 :                         if (Z_TYPE_P(err) == IS_LONG) {
     713         380 :                                 EG(error_reporting) = Z_LVAL_P(err);
     714             :                         } else {
     715           0 :                                 EG(error_reporting) = atoi(p->value->val);
     716             :                         }
     717             :                 } while (0);
     718             :         }
     719             : 
     720        2395 :         RETVAL_LONG(old_error_reporting);
     721             : }
     722             : /* }}} */
     723             : 
     724           6 : static int validate_constant_array(HashTable *ht) /* {{{ */
     725             : {
     726           6 :         int ret = 1;
     727             :         zval *val;
     728             : 
     729           6 :         ht->u.v.nApplyCount++;
     730          31 :         ZEND_HASH_FOREACH_VAL_IND(ht, val) {
     731           9 :                 ZVAL_DEREF(val);
     732           9 :                 if (Z_REFCOUNTED_P(val)) {
     733           4 :                         if (Z_TYPE_P(val) == IS_ARRAY) {
     734           2 :                                 if (!Z_IMMUTABLE_P(val)) {
     735           2 :                                         if (Z_ARRVAL_P(val)->u.v.nApplyCount > 0) {
     736           1 :                                                 zend_error(E_WARNING, "Constants cannot be recursive arrays");
     737           1 :                                                 ret = 0;
     738           1 :                                                 break;
     739           1 :                                         } else if (!validate_constant_array(Z_ARRVAL_P(val))) {
     740           0 :                                                 ret = 0;
     741           0 :                                                 break;
     742             :                                         }
     743             :                                 }
     744           3 :                         } else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE) {
     745           1 :                                 zend_error(E_WARNING, "Constants may only evaluate to scalar values or arrays");
     746           1 :                                 ret = 0;
     747           1 :                                 break;
     748             :                         }
     749             :                 }
     750             :         } ZEND_HASH_FOREACH_END();
     751           6 :         ht->u.v.nApplyCount--;
     752           6 :         return ret;
     753             : }
     754             : /* }}} */
     755             : 
     756           4 : static void copy_constant_array(zval *dst, zval *src) /* {{{ */
     757             : {
     758             :         zend_string *key;
     759             :         zend_ulong idx;
     760             :         zval *new_val, *val;
     761             : 
     762           4 :         array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src)));
     763          25 :         ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(src), idx, key, val) {
     764             :                 /* constant arrays can't contain references */
     765           7 :                 if (Z_ISREF_P(val)) {
     766           1 :                         if (Z_REFCOUNT_P(val) == 1) {
     767           0 :                                 ZVAL_UNREF(val);
     768             :                         } else {
     769             :                                 Z_DELREF_P(val);
     770           1 :                                 val = Z_REFVAL_P(val);
     771             :                         }
     772             :                 }
     773           7 :                 if (key) {
     774           1 :                         new_val = zend_hash_add_new(Z_ARRVAL_P(dst), key, val);
     775             :                 } else {
     776           6 :                         new_val = zend_hash_index_add_new(Z_ARRVAL_P(dst), idx, val);
     777             :                 }
     778           7 :                 if (Z_TYPE_P(val) == IS_ARRAY) {
     779           1 :                         if (!Z_IMMUTABLE_P(val)) {
     780           1 :                                 copy_constant_array(new_val, val);
     781             :                         }
     782           6 :                 } else if (Z_REFCOUNTED_P(val)) {
     783             :                         Z_ADDREF_P(val);
     784             :                 }
     785             :         } ZEND_HASH_FOREACH_END();
     786           4 : }
     787             : /* }}} */
     788             : 
     789             : /* {{{ proto bool define(string constant_name, mixed value, boolean case_insensitive=false)
     790             :    Define a new constant */
     791        3307 : ZEND_FUNCTION(define)
     792             : {
     793             :         zend_string *name;
     794             :         zval *val, val_free;
     795        3307 :         zend_bool non_cs = 0;
     796        3307 :         int case_sensitive = CONST_CS;
     797             :         zend_constant c;
     798             : 
     799             : #ifndef FAST_ZPP
     800             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|b", &name, &val, &non_cs) == FAILURE) {
     801             :                 return;
     802             :         }
     803             : #else
     804        3307 :         ZEND_PARSE_PARAMETERS_START(2, 3)
     805        9915 :                 Z_PARAM_STR(name)
     806        3304 :                 Z_PARAM_ZVAL(val)
     807        3304 :                 Z_PARAM_OPTIONAL
     808        3560 :                 Z_PARAM_BOOL(non_cs)
     809        3307 :         ZEND_PARSE_PARAMETERS_END();
     810             : #endif
     811             : 
     812        3303 :         if(non_cs) {
     813         127 :                 case_sensitive = 0;
     814             :         }
     815             : 
     816             :         /* class constant, check if there is name and make sure class is valid & exists */
     817        6606 :         if (zend_memnstr(name->val, "::", sizeof("::") - 1, name->val + name->len)) {
     818           3 :                 zend_error(E_WARNING, "Class constants cannot be defined or redefined");
     819           3 :                 RETURN_FALSE;
     820             :         }
     821             : 
     822        3300 :         ZVAL_UNDEF(&val_free);
     823             : 
     824             : repeat:
     825        6600 :         switch (Z_TYPE_P(val)) {
     826             :                 case IS_LONG:
     827             :                 case IS_DOUBLE:
     828             :                 case IS_STRING:
     829             :                 case IS_FALSE:
     830             :                 case IS_TRUE:
     831             :                 case IS_RESOURCE:
     832             :                 case IS_NULL:
     833        3291 :                         break;
     834             :                 case IS_ARRAY:
     835           5 :                         if (!Z_IMMUTABLE_P(val)) {
     836           5 :                                 if (!validate_constant_array(Z_ARRVAL_P(val))) {
     837           2 :                                         RETURN_FALSE;
     838             :                                 } else {
     839           3 :                                         copy_constant_array(&c.value, val);
     840           3 :                                         goto register_constant;
     841             :                                 }
     842             :                         }
     843           0 :                         break;
     844             :                 case IS_OBJECT:
     845           4 :                         if (Z_TYPE(val_free) == IS_UNDEF) {
     846           4 :                                 if (Z_OBJ_HT_P(val)->get) {
     847             :                                         zval rv;
     848           0 :                                         val = Z_OBJ_HT_P(val)->get(val, &rv);
     849           0 :                                         ZVAL_COPY_VALUE(&val_free, val);
     850           0 :                                         goto repeat;
     851           4 :                                 } else if (Z_OBJ_HT_P(val)->cast_object) {
     852           4 :                                         if (Z_OBJ_HT_P(val)->cast_object(val, &val_free, IS_STRING) == SUCCESS) {
     853           1 :                                                 val = &val_free;
     854           1 :                                                 break;
     855             :                                         }
     856             :                                 }
     857             :                         }
     858             :                         /* no break */
     859             :                 default:
     860           3 :                         zend_error(E_WARNING, "Constants may only evaluate to scalar values or arrays");
     861           3 :                         zval_ptr_dtor(&val_free);
     862           3 :                         RETURN_FALSE;
     863             :         }
     864             : 
     865        3292 :         ZVAL_DUP(&c.value, val);
     866        3292 :         zval_ptr_dtor(&val_free);
     867             : register_constant:
     868        3295 :         c.flags = case_sensitive; /* non persistent */
     869        6590 :         c.name = zend_string_copy(name);
     870        3295 :         c.module_number = PHP_USER_CONSTANT;
     871        3295 :         if (zend_register_constant(&c) == SUCCESS) {
     872        3289 :                 RETURN_TRUE;
     873             :         } else {
     874           6 :                 RETURN_FALSE;
     875             :         }
     876             : }
     877             : /* }}} */
     878             : 
     879             : /* {{{ proto bool defined(string constant_name)
     880             :    Check whether a constant exists
     881             :    Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
     882          23 : ZEND_FUNCTION(defined)
     883             : {
     884             :         zend_string *name;
     885             : 
     886             : #ifndef FAST_ZPP
     887             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
     888             :                 return;
     889             :         }
     890             : #else
     891          23 :         ZEND_PARSE_PARAMETERS_START(1, 1)
     892          69 :                 Z_PARAM_STR(name)
     893          23 :         ZEND_PARSE_PARAMETERS_END();
     894             : #endif
     895             : 
     896          23 :         if (zend_get_constant_ex(name, NULL, ZEND_FETCH_CLASS_SILENT)) {
     897          13 :                 RETURN_TRUE;
     898             :         } else {
     899          10 :                 RETURN_FALSE;
     900             :         }
     901             : }
     902             : /* }}} */
     903             : 
     904             : /* {{{ proto string get_class([object object])
     905             :    Retrieves the class name */
     906         648 : ZEND_FUNCTION(get_class)
     907             : {
     908         648 :         zval *obj = NULL;
     909             : 
     910         648 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o!", &obj) == FAILURE) {
     911          24 :                 RETURN_FALSE;
     912             :         }
     913             : 
     914         624 :         if (!obj) {
     915          12 :                 if (EG(scope)) {
     916          14 :                         RETURN_STR(zend_string_copy(EG(scope)->name));
     917             :                 } else {
     918           5 :                         zend_error(E_WARNING, "get_class() called without object from outside a class");
     919           5 :                         RETURN_FALSE;
     920             :                 }
     921             :         }
     922             : 
     923        1224 :         RETURN_STR(zend_string_copy(Z_OBJCE_P(obj)->name));
     924             : }
     925             : /* }}} */
     926             : 
     927             : /* {{{ proto string get_called_class()
     928             :    Retrieves the "Late Static Binding" class name */
     929          35 : ZEND_FUNCTION(get_called_class)
     930             : {
     931          35 :         if (zend_parse_parameters_none() == FAILURE) {
     932           0 :                 return;
     933             :         }
     934             : 
     935          35 :         if (EX(called_scope)) {
     936          66 :                 RETURN_STR(zend_string_copy(EX(called_scope)->name));
     937           2 :         } else if (!EG(scope))  {
     938           2 :                 zend_error(E_WARNING, "get_called_class() called from outside a class");
     939             :         }
     940           2 :         RETURN_FALSE;
     941             : }
     942             : /* }}} */
     943             : 
     944             : /* {{{ proto string get_parent_class([mixed object])
     945             :    Retrieves the parent class name for object or class or current scope. */
     946          59 : ZEND_FUNCTION(get_parent_class)
     947             : {
     948             :         zval *arg;
     949          59 :         zend_class_entry *ce = NULL;
     950             : 
     951          59 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
     952           1 :                 return;
     953             :         }
     954             : 
     955          58 :         if (!ZEND_NUM_ARGS()) {
     956           5 :                 ce = EG(scope);
     957           5 :                 if (ce && ce->parent) {
     958           4 :                         RETURN_STR(zend_string_copy(ce->parent->name));
     959             :                 } else {
     960           3 :                         RETURN_FALSE;
     961             :                 }
     962             :         }
     963             : 
     964         106 :         if (Z_TYPE_P(arg) == IS_OBJECT) {
     965          17 :                 ce = Z_OBJ_P(arg)->ce;
     966          72 :         } else if (Z_TYPE_P(arg) == IS_STRING) {
     967          12 :             ce = zend_lookup_class(Z_STR_P(arg));
     968             :         }
     969             : 
     970          53 :         if (ce && ce->parent) {
     971          10 :                 RETURN_STR(zend_string_copy(ce->parent->name));
     972             :         } else {
     973          48 :                 RETURN_FALSE;
     974             :         }
     975             : }
     976             : /* }}} */
     977             : 
     978         359 : static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* {{{ */
     979             : {
     980             :         zval *obj;
     981             :         zend_string *class_name;
     982             :         zend_class_entry *instance_ce;
     983             :         zend_class_entry *ce;
     984         359 :         zend_bool allow_string = only_subclass;
     985             :         zend_bool retval;
     986             : 
     987             : #ifndef FAST_ZPP
     988             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS|b", &obj, &class_name, &allow_string) == FAILURE) {
     989             :                 return;
     990             :         }
     991             : #else
     992         359 :         ZEND_PARSE_PARAMETERS_START(2, 3)
     993         355 :                 Z_PARAM_ZVAL(obj)
     994        1065 :                 Z_PARAM_STR(class_name)
     995         344 :                 Z_PARAM_OPTIONAL
     996         510 :                 Z_PARAM_BOOL(allow_string)
     997         359 :         ZEND_PARSE_PARAMETERS_END();
     998             : #endif
     999             :         /*
    1000             :          * allow_string - is_a default is no, is_subclass_of is yes.
    1001             :          *   if it's allowed, then the autoloader will be called if the class does not exist.
    1002             :          *   default behaviour is different, as 'is_a' used to be used to test mixed return values
    1003             :          *   and there is no easy way to deprecate this.
    1004             :          */
    1005             : 
    1006         576 :         if (allow_string && Z_TYPE_P(obj) == IS_STRING) {
    1007          92 :                 instance_ce = zend_lookup_class(Z_STR_P(obj));
    1008          92 :                 if (!instance_ce) {
    1009          48 :                         RETURN_FALSE;
    1010             :                 }
    1011         500 :         } else if (Z_TYPE_P(obj) == IS_OBJECT) {
    1012         100 :                 instance_ce = Z_OBJCE_P(obj);
    1013             :         } else {
    1014         150 :                 RETURN_FALSE;
    1015             :         }
    1016             : 
    1017         144 :         ce = zend_lookup_class_ex(class_name, NULL, 0);
    1018         144 :         if (!ce) {
    1019          63 :                 retval = 0;
    1020             :         } else {
    1021          96 :                 if (only_subclass && instance_ce == ce) {
    1022          15 :                         retval = 0;
    1023             :                 } else {
    1024          66 :                         retval = instanceof_function(instance_ce, ce);
    1025             :                 }
    1026             :         }
    1027             : 
    1028         144 :         RETURN_BOOL(retval);
    1029             : }
    1030             : /* }}} */
    1031             : 
    1032             : /* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string=true])
    1033             :    Returns true if the object has this class as one of its parents */
    1034         199 : ZEND_FUNCTION(is_subclass_of)
    1035             : {
    1036         199 :         is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    1037         199 : }
    1038             : /* }}} */
    1039             : 
    1040             : /* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string=false])
    1041             :    Returns true if the first argument is an object and is this class or has this class as one of its parents, */
    1042         160 : ZEND_FUNCTION(is_a)
    1043             : {
    1044         160 :         is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    1045         160 : }
    1046             : /* }}} */
    1047             : 
    1048             : /* {{{ add_class_vars */
    1049          76 : static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value)
    1050             : {
    1051             :         zend_property_info *prop_info;
    1052             :         zval *prop, prop_copy;
    1053             :         zend_string *key;
    1054             : 
    1055         884 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
    1056        1380 :                 if (((prop_info->flags & ZEND_ACC_SHADOW) &&
    1057          18 :                      prop_info->ce != EG(scope)) ||
    1058         388 :                     ((prop_info->flags & ZEND_ACC_PROTECTED) &&
    1059          80 :                      !zend_check_protected(prop_info->ce, EG(scope))) ||
    1060         364 :                     ((prop_info->flags & ZEND_ACC_PRIVATE) &&
    1061          74 :                       ce != EG(scope) &&
    1062          52 :                           prop_info->ce != EG(scope))) {
    1063          92 :                         continue;
    1064             :                 }
    1065         312 :                 prop = NULL;
    1066         350 :                 if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
    1067          38 :                         prop = &ce->default_static_members_table[prop_info->offset];
    1068         274 :                 } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
    1069         118 :                         prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
    1070             :                 }
    1071         468 :                 if (!prop || Z_TYPE_P(prop) == IS_UNDEF) {
    1072         156 :                         continue;
    1073             :                 }
    1074             : 
    1075             :                 /* copy: enforce read only access */
    1076         156 :                 ZVAL_DEREF(prop);
    1077         156 :                 if (UNEXPECTED(Z_COPYABLE_P(prop))) {
    1078          35 :                         ZVAL_DUP(&prop_copy, prop);
    1079          35 :                         prop = &prop_copy;
    1080             :                 }
    1081             : 
    1082             :                 /* this is necessary to make it able to work with default array
    1083             :                  * properties, returned to user */
    1084         156 :                 if (Z_OPT_CONSTANT_P(prop)) {
    1085           0 :                         zval_update_constant(prop, 0);
    1086             :                 }
    1087             : 
    1088         156 :                 zend_hash_add_new(Z_ARRVAL_P(return_value), key, prop);
    1089             :         } ZEND_HASH_FOREACH_END();
    1090          76 : }
    1091             : /* }}} */
    1092             : 
    1093             : /* {{{ proto array get_class_vars(string class_name)
    1094             :    Returns an array of default properties of the class. */
    1095          65 : ZEND_FUNCTION(get_class_vars)
    1096             : {
    1097             :         zend_string *class_name;
    1098             :         zend_class_entry *ce;
    1099             : 
    1100          65 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
    1101           7 :                 return;
    1102             :         }
    1103             : 
    1104          58 :         ce = zend_lookup_class(class_name);
    1105          58 :         if (!ce) {
    1106          20 :                 RETURN_FALSE;
    1107             :         } else {
    1108          38 :                 array_init(return_value);
    1109          38 :                 zend_update_class_constants(ce);
    1110          38 :                 add_class_vars(ce, 0, return_value);
    1111          38 :                 add_class_vars(ce, 1, return_value);
    1112             :         }
    1113             : }
    1114             : /* }}} */
    1115             : 
    1116             : /* {{{ proto array get_object_vars(object obj)
    1117             :    Returns an array of object properties */
    1118          73 : ZEND_FUNCTION(get_object_vars)
    1119             : {
    1120             :         zval *obj;
    1121             :         zval *value;
    1122             :         HashTable *properties;
    1123             :         zend_string *key;
    1124             :         zend_object *zobj;
    1125             : 
    1126             : #ifndef FAST_ZPP
    1127             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
    1128             :                 return;
    1129             :         }
    1130             : #else
    1131          73 :         ZEND_PARSE_PARAMETERS_START(1, 1)
    1132         213 :                 Z_PARAM_OBJECT(obj)
    1133          73 :         ZEND_PARSE_PARAMETERS_END();
    1134             : #endif
    1135             : 
    1136          45 :         if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
    1137           0 :                 RETURN_FALSE;
    1138             :         }
    1139             : 
    1140          45 :         properties = Z_OBJ_HT_P(obj)->get_properties(obj);
    1141             : 
    1142          45 :         if (properties == NULL) {
    1143           0 :                 RETURN_FALSE;
    1144             :         }
    1145             : 
    1146          45 :         zobj = Z_OBJ_P(obj);
    1147             : 
    1148          52 :         if (!zobj->ce->default_properties_count && properties == zobj->properties) {
    1149             :                 /* fast copy */
    1150           7 :                 ZVAL_NEW_ARR(return_value);
    1151           7 :                 zend_array_dup(Z_ARRVAL_P(return_value), properties);
    1152             :         } else {
    1153          38 :                 array_init_size(return_value, zend_hash_num_elements(properties));
    1154             : 
    1155         647 :                 ZEND_HASH_FOREACH_STR_KEY_VAL_IND(properties, key, value) {
    1156         203 :                         if (key) {
    1157         200 :                                 if (zend_check_property_access(zobj, key) == SUCCESS) {
    1158             :                                         /* Not separating references */
    1159         172 :                                         if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
    1160         172 :                                         if (key->val[0] == 0) {
    1161             :                                                 const char *prop_name, *class_name;
    1162             :                                                 size_t prop_len;
    1163          37 :                                                 zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
    1164          37 :                                                 zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value);
    1165             :                                         } else {
    1166         135 :                                                 zend_hash_add_new(Z_ARRVAL_P(return_value), key, value);
    1167             :                                         }
    1168             :                                 }
    1169             :                         }
    1170             :                 } ZEND_HASH_FOREACH_END();
    1171             :         }
    1172             : }
    1173             : /* }}} */
    1174             : 
    1175          56 : static int same_name(zend_string *key, zend_string *name) /* {{{ */
    1176             : {
    1177             :         zend_string *lcname;
    1178             :         int ret;
    1179             : 
    1180          56 :         if (key == name) {
    1181          18 :                 return 1;
    1182             :         }
    1183          38 :         if (key->len != name->len) {
    1184           3 :                 return 0;
    1185             :         }
    1186          35 :         lcname = zend_string_tolower(name);
    1187          35 :         ret = memcmp(lcname->val, key->val, key->len) == 0;
    1188             :         zend_string_release(lcname);
    1189          35 :         return ret;
    1190             : }
    1191             : /* }}} */
    1192             : 
    1193             : /* {{{ proto array get_class_methods(mixed class)
    1194             :    Returns an array of method names for class or class instance. */
    1195          73 : ZEND_FUNCTION(get_class_methods)
    1196             : {
    1197             :         zval *klass;
    1198             :         zval method_name;
    1199          73 :         zend_class_entry *ce = NULL;
    1200             :         zend_function *mptr;
    1201             :         zend_string *key;
    1202             : 
    1203          73 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &klass) == FAILURE) {
    1204           2 :                 return;
    1205             :         }
    1206             : 
    1207         142 :         if (Z_TYPE_P(klass) == IS_OBJECT) {
    1208          10 :                 ce = Z_OBJCE_P(klass);
    1209         122 :         } else if (Z_TYPE_P(klass) == IS_STRING) {
    1210          39 :             ce = zend_lookup_class(Z_STR_P(klass));
    1211             :         }
    1212             : 
    1213          71 :         if (!ce) {
    1214          27 :                 RETURN_NULL();
    1215             :         }
    1216             : 
    1217          44 :         array_init(return_value);
    1218             : 
    1219         532 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) {
    1220             : 
    1221         428 :                 if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
    1222          63 :                  || (EG(scope) &&
    1223          46 :                      (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
    1224          22 :                        zend_check_protected(mptr->common.scope, EG(scope)))
    1225          29 :                    || ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
    1226          24 :                        EG(scope) == mptr->common.scope)))) {
    1227         206 :                         size_t len = mptr->common.function_name->len;
    1228             : 
    1229             :                         /* Do not display old-style inherited constructors */
    1230         206 :                         if (!key) {
    1231           0 :                                 ZVAL_STR_COPY(&method_name, mptr->common.function_name);
    1232           0 :                                 zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
    1233         229 :                         } else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
    1234          16 :                             mptr->common.scope == ce ||
    1235           7 :                             zend_binary_strcasecmp(key->val, key->len, mptr->common.function_name->val, len) == 0) {
    1236             : 
    1237         375 :                                 if (mptr->type == ZEND_USER_FUNCTION &&
    1238         112 :                                     *mptr->op_array.refcount > 1 &&
    1239          54 :                                  !same_name(key, mptr->common.function_name)) {
    1240           3 :                                         ZVAL_STR_COPY(&method_name, zend_find_alias_name(mptr->common.scope, key));
    1241           3 :                                         zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
    1242             :                                 } else {
    1243         203 :                                         ZVAL_STR_COPY(&method_name, mptr->common.function_name);
    1244         203 :                                         zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
    1245             :                                 }
    1246             :                         }
    1247             :                 }
    1248             :         } ZEND_HASH_FOREACH_END();
    1249             : }
    1250             : /* }}} */
    1251             : 
    1252             : /* {{{ proto bool method_exists(object object, string method)
    1253             :    Checks if the class method exists */
    1254         132 : ZEND_FUNCTION(method_exists)
    1255             : {
    1256             :         zval *klass;
    1257             :         zend_string *method_name;
    1258             :         zend_string *lcname;
    1259             :         zend_class_entry * ce;
    1260             : 
    1261             : #ifndef FAST_ZPP
    1262             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &klass, &method_name) == FAILURE) {
    1263             :                 return;
    1264             :         }
    1265             : #else
    1266         132 :         ZEND_PARSE_PARAMETERS_START(2, 2)
    1267         130 :                 Z_PARAM_ZVAL(klass)
    1268         390 :                 Z_PARAM_STR(method_name)
    1269         132 :         ZEND_PARSE_PARAMETERS_END();
    1270             : #endif
    1271         248 :         if (Z_TYPE_P(klass) == IS_OBJECT) {
    1272          70 :                 ce = Z_OBJCE_P(klass);
    1273         108 :         } else if (Z_TYPE_P(klass) == IS_STRING) {
    1274          32 :                 if ((ce = zend_lookup_class(Z_STR_P(klass))) == NULL) {
    1275           5 :                         RETURN_FALSE;
    1276             :                 }
    1277             :         } else {
    1278          22 :                 RETURN_FALSE;
    1279             :         }
    1280             : 
    1281          97 :         lcname = zend_string_tolower(method_name);
    1282          97 :         if (zend_hash_exists(&ce->function_table, lcname)) {
    1283             :                 zend_string_release(lcname);
    1284          65 :                 RETURN_TRUE;
    1285             :         } else {
    1286          32 :                 union _zend_function *func = NULL;
    1287             : 
    1288          90 :                 if (Z_TYPE_P(klass) == IS_OBJECT
    1289          61 :                 && Z_OBJ_HT_P(klass)->get_method != NULL
    1290          58 :                 && (func = Z_OBJ_HT_P(klass)->get_method(&Z_OBJ_P(klass), method_name, NULL)) != NULL
    1291             :                 ) {
    1292           6 :                         if (func->type == ZEND_INTERNAL_FUNCTION
    1293           6 :                         && (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0
    1294             :                         ) {
    1295             :                                 /* Returns true to the fake Closure's __invoke */
    1296           3 :                                 RETVAL_BOOL(func->common.scope == zend_ce_closure
    1297             :                                         && zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
    1298             : 
    1299             :                                 zend_string_release(lcname);
    1300           3 :                                 zend_string_release(func->common.function_name);
    1301           3 :                                 efree(func);
    1302           3 :                                 return;
    1303             :                         }
    1304             :                         zend_string_release(lcname);
    1305           0 :                         RETURN_TRUE;
    1306             :                 }
    1307             :         }
    1308             :         zend_string_release(lcname);
    1309          29 :         RETURN_FALSE;
    1310             : }
    1311             : /* }}} */
    1312             : 
    1313             : /* {{{ proto bool property_exists(mixed object_or_class, string property_name)
    1314             :    Checks if the object or class has a property */
    1315         128 : ZEND_FUNCTION(property_exists)
    1316             : {
    1317             :         zval *object;
    1318             :         zend_string *property;
    1319             :         zend_class_entry *ce;
    1320             :         zend_property_info *property_info;
    1321             :         zval property_z;
    1322             : 
    1323         128 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &object, &property) == FAILURE) {
    1324           4 :                 return;
    1325             :         }
    1326             : 
    1327         124 :         if (property == NULL) {
    1328           0 :                 RETURN_FALSE;
    1329             :         }
    1330             : 
    1331         248 :         if (Z_TYPE_P(object) == IS_STRING) {
    1332          68 :                 ce = zend_lookup_class(Z_STR_P(object));
    1333          68 :                 if (!ce) {
    1334           4 :                         RETURN_FALSE;
    1335             :                 }
    1336         112 :         } else if (Z_TYPE_P(object) == IS_OBJECT) {
    1337          50 :                 ce = Z_OBJCE_P(object);
    1338             :         } else {
    1339           6 :                 zend_error(E_WARNING, "First parameter must either be an object or the name of an existing class");
    1340           6 :                 RETURN_NULL();
    1341             :         }
    1342             : 
    1343         305 :         if ((property_info = zend_hash_find_ptr(&ce->properties_info, property)) != NULL
    1344          77 :                 && (property_info->flags & ZEND_ACC_SHADOW) == 0) {
    1345          70 :                 RETURN_TRUE;
    1346             :         }
    1347             : 
    1348          44 :         ZVAL_STR(&property_z, property);
    1349             : 
    1350         140 :         if (Z_TYPE_P(object) ==  IS_OBJECT &&
    1351          26 :                 Z_OBJ_HANDLER_P(object, has_property) &&
    1352          26 :                 Z_OBJ_HANDLER_P(object, has_property)(object, &property_z, 2, NULL)) {
    1353          11 :                 RETURN_TRUE;
    1354             :         }
    1355          33 :         RETURN_FALSE;
    1356             : }
    1357             : /* }}} */
    1358             : 
    1359             : /* {{{ proto bool class_exists(string classname [, bool autoload])
    1360             :    Checks if the class exists */
    1361         498 : ZEND_FUNCTION(class_exists)
    1362             : {
    1363             :         zend_string *class_name;
    1364             :         zend_string *lc_name;
    1365             :         zend_class_entry *ce;
    1366         498 :         zend_bool autoload = 1;
    1367             : 
    1368             : #ifndef FAST_ZPP
    1369             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &class_name, &autoload) == FAILURE) {
    1370             :                 return;
    1371             :         }
    1372             : #else
    1373         498 :         ZEND_PARSE_PARAMETERS_START(1, 2)
    1374        1485 :                 Z_PARAM_STR(class_name)
    1375         487 :                 Z_PARAM_OPTIONAL
    1376         703 :                 Z_PARAM_BOOL(autoload)
    1377         498 :         ZEND_PARSE_PARAMETERS_END();
    1378             : #endif
    1379             : 
    1380         481 :         if (!autoload) {
    1381          54 :                 if (class_name->val[0] == '\\') {
    1382             :                         /* Ignore leading "\" */
    1383           0 :                         lc_name = zend_string_alloc(class_name->len - 1, 0);
    1384           0 :                         zend_str_tolower_copy(lc_name->val, class_name->val + 1, class_name->len - 1);
    1385             :                 } else {
    1386          54 :                         lc_name = zend_string_tolower(class_name);
    1387             :                 }
    1388         108 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1389             :                 zend_string_release(lc_name);
    1390          54 :                 RETURN_BOOL(ce && !((ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
    1391             :         }
    1392             : 
    1393         427 :         ce = zend_lookup_class(class_name);
    1394         427 :         if (ce) {
    1395         353 :                 RETURN_BOOL((ce->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0);
    1396             :         } else {
    1397          74 :                 RETURN_FALSE;
    1398             :         }
    1399             : }
    1400             : /* }}} */
    1401             : 
    1402             : /* {{{ proto bool interface_exists(string classname [, bool autoload])
    1403             :    Checks if the class exists */
    1404         105 : ZEND_FUNCTION(interface_exists)
    1405             : {
    1406             :         zend_string *iface_name, *lc_name;
    1407             :         zend_class_entry *ce;
    1408         105 :         zend_bool autoload = 1;
    1409             : 
    1410             : #ifndef FAST_ZPP
    1411             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &iface_name, &autoload) == FAILURE) {
    1412             :                 return;
    1413             :         }
    1414             : #else
    1415         105 :         ZEND_PARSE_PARAMETERS_START(1, 2)
    1416         306 :                 Z_PARAM_STR(iface_name)
    1417          95 :                 Z_PARAM_OPTIONAL
    1418         211 :                 Z_PARAM_BOOL(autoload)
    1419         105 :         ZEND_PARSE_PARAMETERS_END();
    1420             : #endif
    1421             : 
    1422          89 :         if (!autoload) {
    1423          17 :                 if (iface_name->val[0] == '\\') {
    1424             :                         /* Ignore leading "\" */
    1425           0 :                         lc_name = zend_string_alloc(iface_name->len - 1, 0);
    1426           0 :                         zend_str_tolower_copy(lc_name->val, iface_name->val + 1, iface_name->len - 1);
    1427             :                 } else {
    1428          17 :                         lc_name = zend_string_tolower(iface_name);
    1429             :                 }
    1430          34 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1431             :                 zend_string_release(lc_name);
    1432          17 :                 RETURN_BOOL(ce && ce->ce_flags & ZEND_ACC_INTERFACE);
    1433             :         }
    1434             : 
    1435          72 :         ce = zend_lookup_class(iface_name);
    1436          72 :         if (ce) {
    1437          33 :                 RETURN_BOOL((ce->ce_flags & ZEND_ACC_INTERFACE) > 0);
    1438             :         } else {
    1439          39 :                 RETURN_FALSE;
    1440             :         }
    1441             : }
    1442             : /* }}} */
    1443             : 
    1444             : /* {{{ proto bool trait_exists(string traitname [, bool autoload])
    1445             :  Checks if the trait exists */
    1446          73 : ZEND_FUNCTION(trait_exists)
    1447             : {
    1448             :         zend_string *trait_name, *lc_name;
    1449             :         zend_class_entry *ce;
    1450          73 :         zend_bool autoload = 1;
    1451             : 
    1452             : #ifndef FAST_ZPP
    1453             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &trait_name, &autoload) == FAILURE) {
    1454             :                 return;
    1455             :         }
    1456             : #else
    1457          73 :         ZEND_PARSE_PARAMETERS_START(1, 2)
    1458         213 :                 Z_PARAM_STR(trait_name)
    1459          64 :                 Z_PARAM_OPTIONAL
    1460         164 :                 Z_PARAM_BOOL(autoload)
    1461          73 :         ZEND_PARSE_PARAMETERS_END();
    1462             : #endif
    1463             : 
    1464          58 :         if (!autoload) {
    1465          11 :                 if (trait_name->val[0] == '\\') {
    1466             :                         /* Ignore leading "\" */
    1467           0 :                         lc_name = zend_string_alloc(trait_name->len - 1, 0);
    1468           0 :                         zend_str_tolower_copy(lc_name->val, trait_name->val + 1, trait_name->len - 1);
    1469             :                 } else {
    1470          11 :                         lc_name = zend_string_tolower(trait_name);
    1471             :                 }
    1472          22 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1473             :                 zend_string_release(lc_name);
    1474          11 :                 RETURN_BOOL(ce && ((ce->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
    1475             :         }
    1476             : 
    1477          47 :         ce = zend_lookup_class(trait_name);
    1478          47 :         if (ce) {
    1479          11 :                 RETURN_BOOL((ce->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
    1480             :         } else {
    1481          36 :                 RETURN_FALSE;
    1482             :         }
    1483             : }
    1484             : /* }}} */
    1485             : 
    1486             : /* {{{ proto bool function_exists(string function_name)
    1487             :    Checks if the function exists */
    1488        4395 : ZEND_FUNCTION(function_exists)
    1489             : {
    1490             :         zend_string *name;
    1491             :         zend_function *func;
    1492             :         zend_string *lcname;
    1493             : 
    1494             : #ifndef FAST_ZPP
    1495             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    1496             :                 return;
    1497             :         }
    1498             : #else
    1499        4395 :         ZEND_PARSE_PARAMETERS_START(1, 1)
    1500       13179 :                 Z_PARAM_STR(name)
    1501        4395 :         ZEND_PARSE_PARAMETERS_END();
    1502             : #endif
    1503             : 
    1504        4389 :         if (name->val[0] == '\\') {
    1505             :                 /* Ignore leading "\" */
    1506           2 :                 lcname = zend_string_alloc(name->len - 1, 0);
    1507           1 :                 zend_str_tolower_copy(lcname->val, name->val + 1, name->len - 1);
    1508             :         } else {
    1509        4388 :                 lcname = zend_string_tolower(name);
    1510             :         }
    1511             : 
    1512        8778 :         func = zend_hash_find_ptr(EG(function_table), lcname);
    1513             :         zend_string_release(lcname);
    1514             : 
    1515             :         /*
    1516             :          * A bit of a hack, but not a bad one: we see if the handler of the function
    1517             :          * is actually one that displays "function is disabled" message.
    1518             :          */
    1519        4389 :         RETURN_BOOL(func && (func->type != ZEND_INTERNAL_FUNCTION ||
    1520             :                 func->internal_function.handler != zif_display_disabled_function));
    1521             : }
    1522             : /* }}} */
    1523             : 
    1524             : /* {{{ proto bool class_alias(string user_class_name , string alias_name [, bool autoload])
    1525             :    Creates an alias for user defined class */
    1526          28 : ZEND_FUNCTION(class_alias)
    1527             : {
    1528             :         zend_string *class_name;
    1529             :         char *alias_name;
    1530             :         zend_class_entry *ce;
    1531             :         size_t alias_name_len;
    1532          28 :         zend_bool autoload = 1;
    1533             : 
    1534          28 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ss|b", &class_name, &alias_name, &alias_name_len, &autoload) == FAILURE) {
    1535           0 :                 return;
    1536             :         }
    1537             : 
    1538          28 :         ce = zend_lookup_class_ex(class_name, NULL, autoload);
    1539             : 
    1540          28 :         if (ce) {
    1541          27 :                 if (ce->type == ZEND_USER_CLASS) {
    1542          26 :                         if (zend_register_class_alias_ex(alias_name, alias_name_len, ce) == SUCCESS) {
    1543          22 :                                 RETURN_TRUE;
    1544             :                         } else {
    1545           4 :                                 zend_error(E_WARNING, "Cannot redeclare class %s", alias_name);
    1546           4 :                                 RETURN_FALSE;
    1547             :                         }
    1548             :                 } else {
    1549           1 :                         zend_error(E_WARNING, "First argument of class_alias() must be a name of user defined class");
    1550           1 :                         RETURN_FALSE;
    1551             :                 }
    1552             :         } else {
    1553           1 :                 zend_error(E_WARNING, "Class '%s' not found", class_name->val);
    1554           1 :                 RETURN_FALSE;
    1555             :         }
    1556             : }
    1557             : /* }}} */
    1558             : 
    1559             : #if ZEND_DEBUG
    1560             : /* {{{ proto void leak(int num_bytes=3)
    1561             :    Cause an intentional memory leak, for testing/debugging purposes */
    1562             : ZEND_FUNCTION(leak)
    1563             : {
    1564             :         zend_long leakbytes=3;
    1565             : 
    1566             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &leakbytes) == FAILURE) {
    1567             :                 return;
    1568             :         }
    1569             : 
    1570             :         emalloc(leakbytes);
    1571             : }
    1572             : /* }}} */
    1573             : 
    1574             : /* {{{ proto leak_variable(mixed variable [, bool leak_data]) */
    1575             : ZEND_FUNCTION(leak_variable)
    1576             : {
    1577             :         zval *zv;
    1578             :         zend_bool leak_data = 0;
    1579             : 
    1580             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &zv, &leak_data) == FAILURE) {
    1581             :                 return;
    1582             :         }
    1583             : 
    1584             :         if (!leak_data) {
    1585             :                 Z_ADDREF_P(zv);
    1586             :         } else if (Z_TYPE_P(zv) == IS_RESOURCE) {
    1587             :                 Z_ADDREF_P(zv);
    1588             :         } else if (Z_TYPE_P(zv) == IS_OBJECT) {
    1589             :                 Z_ADDREF_P(zv);
    1590             :         } else {
    1591             :                 zend_error(E_WARNING, "Leaking non-zval data is only applicable to resources and objects");
    1592             :         }
    1593             : }
    1594             : /* }}} */
    1595             : 
    1596             : 
    1597             : #ifdef ZEND_TEST_EXCEPTIONS
    1598             : ZEND_FUNCTION(crash)
    1599             : {
    1600             :         char *nowhere=NULL;
    1601             : 
    1602             :         memcpy(nowhere, "something", sizeof("something"));
    1603             : }
    1604             : #endif
    1605             : 
    1606             : #endif /* ZEND_DEBUG */
    1607             : 
    1608             : /* {{{ proto array get_included_files(void)
    1609             :    Returns an array with the file names that were include_once()'d */
    1610          39 : ZEND_FUNCTION(get_included_files)
    1611             : {
    1612             :         zend_string *entry;
    1613             : 
    1614          39 :         if (zend_parse_parameters_none() == FAILURE) {
    1615           3 :                 return;
    1616             :         }
    1617             : 
    1618          36 :         array_init(return_value);
    1619         178 :         ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), entry) {
    1620          71 :                 if (entry) {
    1621          71 :                         add_next_index_str(return_value, zend_string_copy(entry));
    1622             :                 }
    1623             :         } ZEND_HASH_FOREACH_END();
    1624             : }
    1625             : /* }}} */
    1626             : 
    1627             : /* {{{ proto void trigger_error(string message [, int error_type])
    1628             :    Generates a user-level error/warning/notice message */
    1629          24 : ZEND_FUNCTION(trigger_error)
    1630             : {
    1631          24 :         zend_long error_type = E_USER_NOTICE;
    1632             :         char *message;
    1633             :         size_t message_len;
    1634             : 
    1635          24 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &message, &message_len, &error_type) == FAILURE) {
    1636           2 :                 return;
    1637             :         }
    1638             : 
    1639          22 :         switch (error_type) {
    1640             :                 case E_USER_ERROR:
    1641             :                 case E_USER_WARNING:
    1642             :                 case E_USER_NOTICE:
    1643             :                 case E_USER_DEPRECATED:
    1644          20 :                         break;
    1645             :                 default:
    1646           2 :                         zend_error(E_WARNING, "Invalid error type specified");
    1647           2 :                         RETURN_FALSE;
    1648             :                         break;
    1649             :         }
    1650             : 
    1651          20 :         zend_error((int)error_type, "%s", message);
    1652          19 :         RETURN_TRUE;
    1653             : }
    1654             : /* }}} */
    1655             : 
    1656             : /* {{{ proto string set_error_handler(string error_handler [, int error_types])
    1657             :    Sets a user-defined error handler function.  Returns the previously defined error handler, or false on error */
    1658         280 : ZEND_FUNCTION(set_error_handler)
    1659             : {
    1660             :         zval *error_handler;
    1661         280 :         zend_string *error_handler_name = NULL;
    1662         280 :         zend_long error_type = E_ALL;
    1663             : 
    1664         280 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &error_handler, &error_type) == FAILURE) {
    1665           0 :                 return;
    1666             :         }
    1667             : 
    1668         560 :         if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
    1669         279 :                 if (!zend_is_callable(error_handler, 0, &error_handler_name)) {
    1670           0 :                         zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
    1671           0 :                                            get_active_function_name(), error_handler_name?error_handler_name->val:"unknown");
    1672           0 :                         zend_string_release(error_handler_name);
    1673           0 :                         return;
    1674             :                 }
    1675         279 :                 zend_string_release(error_handler_name);
    1676             :         }
    1677             : 
    1678         280 :         if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
    1679           8 :                 RETVAL_ZVAL(&EG(user_error_handler), 1, 0);
    1680             : 
    1681           4 :                 zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
    1682           4 :                 zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
    1683             :         }
    1684             : 
    1685         560 :         if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
    1686           1 :                 ZVAL_UNDEF(&EG(user_error_handler));
    1687           1 :                 return;
    1688             :         }
    1689             : 
    1690         279 :         ZVAL_DUP(&EG(user_error_handler), error_handler);
    1691         279 :         EG(user_error_handler_error_reporting) = (int)error_type;
    1692             : }
    1693             : /* }}} */
    1694             : 
    1695             : /* {{{ proto void restore_error_handler(void)
    1696             :    Restores the previously defined error handler function */
    1697           2 : ZEND_FUNCTION(restore_error_handler)
    1698             : {
    1699           2 :         if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
    1700             :                 zval zeh;
    1701             : 
    1702           2 :                 ZVAL_COPY_VALUE(&zeh, &EG(user_error_handler));
    1703           2 :                 ZVAL_UNDEF(&EG(user_error_handler));
    1704           2 :                 zval_ptr_dtor(&zeh);
    1705             :         }
    1706             : 
    1707           2 :         if (zend_stack_is_empty(&EG(user_error_handlers))) {
    1708           2 :                 ZVAL_UNDEF(&EG(user_error_handler));
    1709             :         } else {
    1710             :                 zval *tmp;
    1711           0 :                 EG(user_error_handler_error_reporting) = zend_stack_int_top(&EG(user_error_handlers_error_reporting));
    1712           0 :                 zend_stack_del_top(&EG(user_error_handlers_error_reporting));
    1713           0 :                 tmp = zend_stack_top(&EG(user_error_handlers));
    1714           0 :                 ZVAL_COPY_VALUE(&EG(user_error_handler), tmp);
    1715           0 :                 zend_stack_del_top(&EG(user_error_handlers));
    1716             :         }
    1717           2 :         RETURN_TRUE;
    1718             : }
    1719             : /* }}} */
    1720             : 
    1721             : /* {{{ proto string set_exception_handler(callable exception_handler)
    1722             :    Sets a user-defined exception handler function.  Returns the previously defined exception handler, or false on error */
    1723          19 : ZEND_FUNCTION(set_exception_handler)
    1724             : {
    1725             :         zval *exception_handler;
    1726          19 :         zend_string *exception_handler_name = NULL;
    1727             : 
    1728          19 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &exception_handler) == FAILURE) {
    1729           2 :                 return;
    1730             :         }
    1731             : 
    1732          34 :         if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
    1733          16 :                 if (!zend_is_callable(exception_handler, 0, &exception_handler_name)) {
    1734           4 :                         zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
    1735           4 :                                            get_active_function_name(), exception_handler_name?exception_handler_name->val:"unknown");
    1736           2 :                         zend_string_release(exception_handler_name);
    1737           2 :                         return;
    1738             :                 }
    1739          14 :                 zend_string_release(exception_handler_name);
    1740             :         }
    1741             : 
    1742          15 :         if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
    1743           6 :                 RETVAL_ZVAL(&EG(user_exception_handler), 1, 0);
    1744             : 
    1745           3 :                 zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
    1746             :         }
    1747             : 
    1748          30 :         if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
    1749           1 :                 ZVAL_UNDEF(&EG(user_exception_handler));
    1750           1 :                 return;
    1751             :         }
    1752             : 
    1753          14 :         ZVAL_DUP(&EG(user_exception_handler), exception_handler);
    1754             : }
    1755             : /* }}} */
    1756             : 
    1757             : /* {{{ proto void restore_exception_handler(void)
    1758             :    Restores the previously defined exception handler function */
    1759           1 : ZEND_FUNCTION(restore_exception_handler)
    1760             : {
    1761           1 :         if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
    1762           1 :                 zval_ptr_dtor(&EG(user_exception_handler));
    1763             :         }
    1764           1 :         if (zend_stack_is_empty(&EG(user_exception_handlers))) {
    1765           0 :                 ZVAL_UNDEF(&EG(user_exception_handler));
    1766             :         } else {
    1767           1 :                 zval *tmp = zend_stack_top(&EG(user_exception_handlers));
    1768           1 :                 ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
    1769           1 :                 zend_stack_del_top(&EG(user_exception_handlers));
    1770             :         }
    1771           1 :         RETURN_TRUE;
    1772             : }
    1773             : /* }}} */
    1774             : 
    1775        5048 : static int copy_class_or_interface_name(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
    1776             : {
    1777        5048 :         zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
    1778        5048 :         zval *array = va_arg(args, zval *);
    1779        5048 :         uint32_t mask = va_arg(args, uint32_t);
    1780        5048 :         uint32_t comply = va_arg(args, uint32_t);
    1781        5048 :         uint32_t comply_mask = (comply)? mask:0;
    1782             : 
    1783       10092 :         if ((hash_key->key && hash_key->key->val[0] != 0)
    1784        5044 :                 && (comply_mask == (ce->ce_flags & mask))) {
    1785        1777 :                 if (ce->refcount > 1 &&
    1786           2 :                     !same_name(hash_key->key, ce->name)) {
    1787           2 :                         add_next_index_str(array, zend_string_copy(hash_key->key));
    1788             :                 } else {
    1789        3546 :                         add_next_index_str(array, zend_string_copy(ce->name));
    1790             :                 }
    1791             :         }
    1792        5048 :         return ZEND_HASH_APPLY_KEEP;
    1793             : }
    1794             : /* }}} */
    1795             : 
    1796             : /* {{{ proto array get_declared_traits()
    1797             :    Returns an array of all declared traits. */
    1798          11 : ZEND_FUNCTION(get_declared_traits)
    1799             : {
    1800          11 :         uint32_t mask = ZEND_ACC_TRAIT;
    1801          11 :         uint32_t comply = 1;
    1802             : 
    1803          11 :         if (zend_parse_parameters_none() == FAILURE) {
    1804           1 :                 return;
    1805             :         }
    1806             : 
    1807          10 :         array_init(return_value);
    1808          10 :         zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
    1809             : }
    1810             : /* }}} */
    1811             : 
    1812             : /* {{{ proto array get_declared_classes()
    1813             :    Returns an array of all declared classes. */
    1814          11 : ZEND_FUNCTION(get_declared_classes)
    1815             : {
    1816          11 :         uint32_t mask = ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
    1817          11 :         uint32_t comply = 0;
    1818             : 
    1819          11 :         if (zend_parse_parameters_none() == FAILURE) {
    1820           1 :                 return;
    1821             :         }
    1822             : 
    1823          10 :         array_init(return_value);
    1824          10 :         zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
    1825             : }
    1826             : /* }}} */
    1827             : 
    1828             : /* {{{ proto array get_declared_interfaces()
    1829             :    Returns an array of all declared interfaces. */
    1830          10 : ZEND_FUNCTION(get_declared_interfaces)
    1831             : {
    1832          10 :         uint32_t mask = ZEND_ACC_INTERFACE;
    1833          10 :         uint32_t comply = 1;
    1834             : 
    1835          10 :         if (zend_parse_parameters_none() == FAILURE) {
    1836           2 :                 return;
    1837             :         }
    1838             : 
    1839           8 :         array_init(return_value);
    1840           8 :         zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
    1841             : }
    1842             : /* }}} */
    1843             : 
    1844        8957 : static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
    1845             : {
    1846        8957 :         zend_function *func = Z_PTR_P(zv);
    1847        8957 :         zval *internal_ar = va_arg(args, zval *),
    1848        8957 :              *user_ar     = va_arg(args, zval *);
    1849             : 
    1850        8957 :         if (hash_key->key == NULL || hash_key->key->val[0] == 0) {
    1851           0 :                 return 0;
    1852             :         }
    1853             : 
    1854        8957 :         if (func->type == ZEND_INTERNAL_FUNCTION) {
    1855       17896 :                 add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
    1856           9 :         } else if (func->type == ZEND_USER_FUNCTION) {
    1857          18 :                 add_next_index_str(user_ar, zend_string_copy(hash_key->key));
    1858             :         }
    1859             : 
    1860        8957 :         return 0;
    1861             : }
    1862             : /* }}} */
    1863             : 
    1864             : /* {{{ proto array get_defined_functions(void)
    1865             :    Returns an array of all defined functions */
    1866           6 : ZEND_FUNCTION(get_defined_functions)
    1867             : {
    1868             :         zval internal, user;
    1869             : 
    1870           6 :         if (zend_parse_parameters_none() == FAILURE) {
    1871           2 :                 return;
    1872             :         }
    1873             : 
    1874           4 :         array_init(&internal);
    1875           4 :         array_init(&user);
    1876           4 :         array_init(return_value);
    1877             : 
    1878           4 :         zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 2, &internal, &user);
    1879             : 
    1880           4 :         zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
    1881           4 :         zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
    1882             : }
    1883             : /* }}} */
    1884             : 
    1885             : /* {{{ proto array get_defined_vars(void)
    1886             :    Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
    1887          18 : ZEND_FUNCTION(get_defined_vars)
    1888             : {
    1889          18 :         zend_array *symbol_table = zend_rebuild_symbol_table();
    1890             : 
    1891          18 :         ZVAL_NEW_ARR(return_value);
    1892          18 :         zend_array_dup(Z_ARRVAL_P(return_value), &symbol_table->ht);
    1893          18 : }
    1894             : /* }}} */
    1895             : 
    1896             : #define LAMBDA_TEMP_FUNCNAME    "__lambda_func"
    1897             : /* {{{ proto string create_function(string args, string code)
    1898             :    Creates an anonymous function, and returns its name (funny, eh?) */
    1899          55 : ZEND_FUNCTION(create_function)
    1900             : {
    1901             :     zend_string *function_name;
    1902             :         char *eval_code, *function_args, *function_code;
    1903             :         size_t eval_code_length, function_args_len, function_code_len;
    1904             :         int retval;
    1905             :         char *eval_name;
    1906             : 
    1907          55 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &function_args, &function_args_len, &function_code, &function_code_len) == FAILURE) {
    1908           0 :                 return;
    1909             :         }
    1910             : 
    1911          55 :         eval_code = (char *) emalloc(sizeof("function " LAMBDA_TEMP_FUNCNAME)
    1912             :                         +function_args_len
    1913             :                         +2      /* for the args parentheses */
    1914             :                         +2      /* for the curly braces */
    1915             :                         +function_code_len);
    1916             : 
    1917          55 :         eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME "(") - 1;
    1918          55 :         memcpy(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(", eval_code_length);
    1919             : 
    1920          55 :         memcpy(eval_code + eval_code_length, function_args, function_args_len);
    1921          55 :         eval_code_length += function_args_len;
    1922             : 
    1923          55 :         eval_code[eval_code_length++] = ')';
    1924          55 :         eval_code[eval_code_length++] = '{';
    1925             : 
    1926          55 :         memcpy(eval_code + eval_code_length, function_code, function_code_len);
    1927          55 :         eval_code_length += function_code_len;
    1928             : 
    1929          55 :         eval_code[eval_code_length++] = '}';
    1930          55 :         eval_code[eval_code_length] = '\0';
    1931             : 
    1932          55 :         eval_name = zend_make_compiled_string_description("runtime-created function");
    1933          55 :         retval = zend_eval_stringl(eval_code, eval_code_length, NULL, eval_name);
    1934          55 :         efree(eval_code);
    1935          55 :         efree(eval_name);
    1936             : 
    1937          55 :         if (retval==SUCCESS) {
    1938             :                 zend_op_array *func;
    1939             :                 HashTable *static_variables;
    1940             : 
    1941         106 :                 func = zend_hash_str_find_ptr(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
    1942          53 :                 if (!func) {
    1943           0 :                         zend_error(E_ERROR, "Unexpected inconsistency in create_function()");
    1944           0 :                         RETURN_FALSE;
    1945             :                 }
    1946          53 :                 (*func->refcount)++;
    1947          53 :                 static_variables = func->static_variables;
    1948          53 :                 func->static_variables = NULL;
    1949          53 :                 zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
    1950          53 :                 func->static_variables = static_variables;
    1951             : 
    1952          53 :                 function_name = zend_string_alloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG, 0);
    1953          53 :                 function_name->val[0] = '\0';
    1954             : 
    1955             :                 do {
    1956          53 :                         function_name->len = snprintf(function_name->val + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)) + 1;
    1957         106 :                 } while (zend_hash_add_ptr(EG(function_table), function_name, func) == NULL);
    1958          53 :                 RETURN_STR(function_name);
    1959             :         } else {
    1960           2 :                 zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
    1961           2 :                 RETURN_FALSE;
    1962             :         }
    1963             : }
    1964             : /* }}} */
    1965             : 
    1966             : #if ZEND_DEBUG
    1967             : ZEND_FUNCTION(zend_test_func)
    1968             : {
    1969             :         zval *arg1, *arg2;
    1970             : 
    1971             :         zend_get_parameters(ZEND_NUM_ARGS(), 2, &arg1, &arg2);
    1972             : }
    1973             : 
    1974             : 
    1975             : #ifdef ZTS
    1976             : ZEND_FUNCTION(zend_thread_id)
    1977             : {
    1978             :         RETURN_LONG((zend_long)tsrm_thread_id());
    1979             : }
    1980             : #endif
    1981             : #endif
    1982             : 
    1983             : /* {{{ proto string get_resource_type(resource res)
    1984             :    Get the resource type name for a given resource */
    1985          77 : ZEND_FUNCTION(get_resource_type)
    1986             : {
    1987             :         const char *resource_type;
    1988             :         zval *z_resource_type;
    1989             : 
    1990          77 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_resource_type) == FAILURE) {
    1991          12 :                 return;
    1992             :         }
    1993             : 
    1994          65 :         resource_type = zend_rsrc_list_get_rsrc_type(Z_RES_P(z_resource_type));
    1995          65 :         if (resource_type) {
    1996          80 :                 RETURN_STRING(resource_type);
    1997             :         } else {
    1998          50 :                 RETURN_STRING("Unknown");
    1999             :         }
    2000             : }
    2001             : /* }}} */
    2002             : 
    2003             : /* {{{ proto array get_resources([string resouce_type])
    2004             :    Get an array with all active resources */
    2005           4 : ZEND_FUNCTION(get_resources)
    2006             : {
    2007           4 :         zend_string *type = NULL;
    2008             :         zend_string *key;
    2009             :         zend_ulong index;
    2010             :         zval *val;
    2011             : 
    2012           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &type) == FAILURE) {
    2013           0 :                 return;
    2014             :         }
    2015             : 
    2016           4 :         if (!type) {
    2017           4 :                 array_init(return_value);
    2018          68 :                 ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
    2019          24 :                         if (!key) {
    2020             :                                 Z_ADDREF_P(val);
    2021          24 :                                 zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
    2022             :                         }
    2023             :                 } ZEND_HASH_FOREACH_END();
    2024           0 :         } else if (zend_string_equals_literal(type, "Unknown")) {
    2025           0 :                 array_init(return_value);
    2026           0 :                 ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
    2027           0 :                         if (!key && Z_RES_TYPE_P(val) <= 0) {
    2028             :                                 Z_ADDREF_P(val);
    2029           0 :                                 zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
    2030             :                         }
    2031             :                 } ZEND_HASH_FOREACH_END();
    2032             :         } else {
    2033           0 :                 int id = zend_fetch_list_dtor_id(type->val);
    2034             : 
    2035           0 :                 if (id <= 0) {
    2036           0 :                         zend_error(E_WARNING, "get_resources():  Unknown resource type '%s'", type->val);
    2037           0 :                         RETURN_FALSE;
    2038             :                 }
    2039             : 
    2040           0 :                 array_init(return_value);
    2041           0 :                 ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
    2042           0 :                         if (!key && Z_RES_TYPE_P(val) == id) {
    2043             :                                 Z_ADDREF_P(val);
    2044           0 :                                 zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
    2045             :                         }
    2046             :                 } ZEND_HASH_FOREACH_END();
    2047             :         }
    2048             : }
    2049             : /* }}} */
    2050             : 
    2051         288 : static int add_extension_info(zval *item, void *arg) /* {{{ */
    2052             : {
    2053         288 :         zval *name_array = (zval *)arg;
    2054         288 :         zend_module_entry *module = (zend_module_entry*)Z_PTR_P(item);
    2055         288 :         add_next_index_string(name_array, module->name);
    2056         288 :         return 0;
    2057             : }
    2058             : /* }}} */
    2059             : 
    2060           2 : static int add_zendext_info(zend_extension *ext, void *arg) /* {{{ */
    2061             : {
    2062           2 :         zval *name_array = (zval *)arg;
    2063           2 :         add_next_index_string(name_array, ext->name);
    2064           2 :         return 0;
    2065             : }
    2066             : /* }}} */
    2067             : 
    2068       27526 : static int add_constant_info(zval *item, void *arg) /* {{{ */
    2069             : {
    2070       27526 :         zval *name_array = (zval *)arg;
    2071       27526 :         zend_constant *constant = (zend_constant*)Z_PTR_P(item);
    2072             :         zval const_val;
    2073             : 
    2074       27526 :         if (!constant->name) {
    2075             :                 /* skip special constants */
    2076           1 :                 return 0;
    2077             :         }
    2078             : 
    2079       27525 :         ZVAL_DUP(&const_val, &constant->value);
    2080       27525 :         zend_hash_add_new(Z_ARRVAL_P(name_array), constant->name, &const_val);
    2081       27525 :         return 0;
    2082             : }
    2083             : /* }}} */
    2084             : 
    2085             : /* {{{ proto array get_loaded_extensions([bool zend_extensions]) U
    2086             :    Return an array containing names of loaded extensions */
    2087           7 : ZEND_FUNCTION(get_loaded_extensions)
    2088             : {
    2089           7 :         zend_bool zendext = 0;
    2090             : 
    2091           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &zendext) == FAILURE) {
    2092           1 :                 return;
    2093             :         }
    2094             : 
    2095           6 :         array_init(return_value);
    2096             : 
    2097           6 :         if (zendext) {
    2098           2 :                 zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t)add_zendext_info, return_value);
    2099             :         } else {
    2100           4 :                 zend_hash_apply_with_argument(&module_registry, add_extension_info, return_value);
    2101             :         }
    2102             : }
    2103             : /* }}} */
    2104             : 
    2105             : /* {{{ proto array get_defined_constants([bool categorize])
    2106             :    Return an array containing the names and values of all defined constants */
    2107          39 : ZEND_FUNCTION(get_defined_constants)
    2108             : {
    2109          39 :         zend_bool categorize = 0;
    2110             : 
    2111          39 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &categorize) == FAILURE) {
    2112           2 :                 return;
    2113             :         }
    2114             : 
    2115          37 :         array_init(return_value);
    2116             : 
    2117          37 :         if (categorize) {
    2118             :                 zend_constant *val;
    2119             :                 int module_number;
    2120             :                 zval *modules, const_val;
    2121             :                 char **module_names;
    2122             :                 zend_module_entry *module;
    2123          26 :                 int i = 1;
    2124             : 
    2125          26 :                 modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval));
    2126          26 :                 module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
    2127             : 
    2128          26 :                 module_names[0] = "internal";
    2129        3770 :                 ZEND_HASH_FOREACH_PTR(&module_registry, module) {
    2130        1872 :                         module_names[module->module_number] = (char *)module->name;
    2131        1872 :                         i++;
    2132             :                 } ZEND_HASH_FOREACH_END();
    2133          26 :                 module_names[i] = "user";
    2134             : 
    2135      130134 :                 ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) {
    2136       65054 :                         if (!val->name) {
    2137             :                                 /* skip special constants */
    2138           1 :                                 continue;
    2139             :                         }
    2140             : 
    2141       65053 :                         if (val->module_number == PHP_USER_CONSTANT) {
    2142           1 :                                 module_number = i;
    2143       65052 :                         } else if (val->module_number > i || val->module_number < 0) {
    2144             :                                 /* should not happen */
    2145           0 :                                 continue;
    2146             :                         } else {
    2147       65052 :                                 module_number = val->module_number;
    2148             :                         }
    2149             : 
    2150      130106 :                         if (Z_TYPE(modules[module_number]) == IS_UNDEF) {
    2151        1145 :                                 array_init(&modules[module_number]);
    2152        1145 :                                 add_assoc_zval(return_value, module_names[module_number], &modules[module_number]);
    2153             :                         }
    2154             : 
    2155       65053 :                         ZVAL_DUP(&const_val, &val->value);
    2156       65053 :                         zend_hash_add_new(Z_ARRVAL(modules[module_number]), val->name, &const_val);
    2157             :                 } ZEND_HASH_FOREACH_END();
    2158             : 
    2159          26 :                 efree(module_names);
    2160          26 :                 efree(modules);
    2161             :         } else {
    2162          11 :                 zend_hash_apply_with_argument(EG(zend_constants), add_constant_info, return_value);
    2163             :         }
    2164             : }
    2165             : /* }}} */
    2166             : 
    2167        2897 : static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /* {{{ */
    2168             : {
    2169        2897 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
    2170             : 
    2171        2897 :         array_init_size(arg_array, num_args);
    2172        2897 :         if (num_args) {
    2173        2452 :                 uint32_t i = 0;
    2174        2452 :                 zval *p = ZEND_CALL_ARG(call, 1);
    2175             : 
    2176        2452 :                 zend_hash_real_init(Z_ARRVAL_P(arg_array), 1);
    2177        2452 :                 ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) {
    2178        2452 :                         if (call->func->type == ZEND_USER_FUNCTION) {
    2179         539 :                                 uint32_t first_extra_arg = call->func->op_array.num_args;
    2180             : 
    2181         539 :                                 if (ZEND_CALL_NUM_ARGS(call) > first_extra_arg) {
    2182         138 :                                         while (i < first_extra_arg) {
    2183          54 :                                                 if (Z_OPT_REFCOUNTED_P(p)) Z_ADDREF_P(p);
    2184          54 :                                                 ZEND_HASH_FILL_ADD(p);
    2185          54 :                                                 zend_hash_next_index_insert_new(Z_ARRVAL_P(arg_array), p);
    2186          54 :                                                 p++;
    2187          54 :                                                 i++;
    2188             :                                         }
    2189          42 :                                         p = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
    2190             :                                 }
    2191             :                         }
    2192             : 
    2193       10179 :                         while (i < num_args) {
    2194        5275 :                                 if (Z_OPT_REFCOUNTED_P(p)) Z_ADDREF_P(p);
    2195        5275 :                                 ZEND_HASH_FILL_ADD(p);
    2196        5275 :                                 p++;
    2197        5275 :                                 i++;
    2198             :                         }
    2199        2452 :                 } ZEND_HASH_FILL_END();
    2200             :         }
    2201        2897 : }
    2202             : /* }}} */
    2203             : 
    2204          42 : void debug_print_backtrace_args(zval *arg_array) /* {{{ */
    2205             : {
    2206             :         zval *tmp;
    2207          42 :         int i = 0;
    2208             : 
    2209         144 :         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arg_array), tmp) {
    2210          51 :                 if (i++) {
    2211          29 :                         ZEND_PUTS(", ");
    2212             :                 }
    2213          51 :                 zend_print_flat_zval_r(tmp);
    2214             :         } ZEND_HASH_FOREACH_END();
    2215          42 : }
    2216             : /* }}} */
    2217             : 
    2218             : /* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
    2219          28 : ZEND_FUNCTION(debug_print_backtrace)
    2220             : {
    2221             :         zend_execute_data *call, *ptr, *skip;
    2222             :         zend_object *object;
    2223          28 :         int lineno, frameno = 0;
    2224             :         zend_function *func;
    2225             :         const char *function_name;
    2226             :         const char *filename;
    2227          28 :         zend_string *class_name = NULL;
    2228             :         char *call_type;
    2229          28 :         const char *include_filename = NULL;
    2230             :         zval arg_array;
    2231          28 :         int indent = 0;
    2232          28 :         zend_long options = 0;
    2233          28 :         zend_long limit = 0;
    2234             : 
    2235          28 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
    2236           0 :                 return;
    2237             :         }
    2238             : 
    2239          28 :         ZVAL_UNDEF(&arg_array);
    2240          28 :         ptr = EX(prev_execute_data);
    2241             : 
    2242             :         /* skip debug_backtrace() */
    2243          28 :         call = ptr;
    2244          28 :         ptr = ptr->prev_execute_data;
    2245             : 
    2246         115 :         while (ptr && (limit == 0 || frameno < limit)) {
    2247          59 :                 frameno++;
    2248          59 :                 class_name = NULL;
    2249          59 :                 call_type = NULL;
    2250          59 :                 ZVAL_UNDEF(&arg_array);
    2251             : 
    2252          59 :                 skip = ptr;
    2253             :                 /* skip internal handler */
    2254          78 :                 if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
    2255           4 :                     skip->prev_execute_data &&
    2256           4 :                     skip->prev_execute_data->func &&
    2257           4 :                     ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
    2258           4 :                     skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
    2259           3 :                     skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
    2260           1 :                         skip = skip->prev_execute_data;
    2261             :                 }
    2262             : 
    2263         115 :                 if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
    2264          56 :                         filename = skip->func->op_array.filename->val;
    2265          56 :                         if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
    2266           0 :                                 if (EG(opline_before_exception)) {
    2267           0 :                                         lineno = EG(opline_before_exception)->lineno;
    2268             :                                 } else {
    2269           0 :                                         lineno = skip->func->op_array.line_end;
    2270             :                                 }
    2271             :                         } else {
    2272          56 :                                 lineno = skip->opline->lineno;
    2273             :                         }
    2274             :                 } else {
    2275           3 :                         filename = NULL;
    2276           3 :                         lineno = 0;
    2277             :                 }
    2278             : 
    2279             :                 /* $this may be passed into regular internal functions */
    2280          59 :                 object = Z_OBJ(call->This);
    2281          75 :                 if (object &&
    2282             :                         call &&
    2283          15 :                     call->func->type == ZEND_INTERNAL_FUNCTION &&
    2284           1 :                     !call->func->common.scope) {
    2285           0 :                         object = NULL;
    2286             :                 }
    2287             : 
    2288          59 :                 if (call->func) {
    2289          57 :                         func = call->func;
    2290         193 :                         function_name = (func->common.scope &&
    2291          29 :                                          func->common.scope->trait_aliases) ?
    2292           6 :                                 zend_resolve_method_name(
    2293             :                                         (object ? object->ce : func->common.scope), func)->val :
    2294          51 :                                 (func->common.function_name ?
    2295          50 :                                         func->common.function_name->val : NULL);
    2296             :                 } else {
    2297           2 :                         func = NULL;
    2298           2 :                         function_name = NULL;
    2299             :                 }
    2300             : 
    2301          59 :                 if (function_name) {
    2302          56 :                         if (object) {
    2303          15 :                                 if (func->common.scope) {
    2304          15 :                                         class_name = func->common.scope->name;
    2305             :                                 } else {
    2306           0 :                                         class_name = object->ce->name;
    2307             :                                 }
    2308             : 
    2309          15 :                                 call_type = "->";
    2310          41 :                         } else if (func->common.scope) {
    2311          14 :                                 class_name = func->common.scope->name;
    2312          14 :                                 call_type = "::";
    2313             :                         } else {
    2314          27 :                                 class_name = NULL;
    2315          27 :                                 call_type = NULL;
    2316             :                         }
    2317          56 :                         if (func->type != ZEND_EVAL_CODE) {
    2318          56 :                                 if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) {
    2319          42 :                                         debug_backtrace_get_args(call, &arg_array);
    2320             :                                 }
    2321             :                         }
    2322             :                 } else {
    2323             :                         /* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
    2324           3 :                         zend_bool build_filename_arg = 1;
    2325             : 
    2326           3 :                         if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
    2327             :                                 /* can happen when calling eval from a custom sapi */
    2328           0 :                                 function_name = "unknown";
    2329           0 :                                 build_filename_arg = 0;
    2330             :                         } else
    2331           3 :                         switch (ptr->opline->extended_value) {
    2332             :                                 case ZEND_EVAL:
    2333           1 :                                         function_name = "eval";
    2334           1 :                                         build_filename_arg = 0;
    2335           1 :                                         break;
    2336             :                                 case ZEND_INCLUDE:
    2337           2 :                                         function_name = "include";
    2338           2 :                                         break;
    2339             :                                 case ZEND_REQUIRE:
    2340           0 :                                         function_name = "require";
    2341           0 :                                         break;
    2342             :                                 case ZEND_INCLUDE_ONCE:
    2343           0 :                                         function_name = "include_once";
    2344           0 :                                         break;
    2345             :                                 case ZEND_REQUIRE_ONCE:
    2346           0 :                                         function_name = "require_once";
    2347           0 :                                         break;
    2348             :                                 default:
    2349             :                                         /* this can actually happen if you use debug_backtrace() in your error_handler and
    2350             :                                          * you're in the top-scope */
    2351           0 :                                         function_name = "unknown";
    2352           0 :                                         build_filename_arg = 0;
    2353             :                                         break;
    2354             :                         }
    2355             : 
    2356           3 :                         if (build_filename_arg && include_filename) {
    2357           0 :                                 array_init(&arg_array);
    2358           0 :                                 add_next_index_string(&arg_array, (char*)include_filename);
    2359             :                         }
    2360           3 :                         call_type = NULL;
    2361             :                 }
    2362          59 :                 zend_printf("#%-2d ", indent);
    2363          59 :                 if (class_name) {
    2364          29 :                         ZEND_PUTS(class_name->val);
    2365          29 :                         ZEND_PUTS(call_type);
    2366             :                 }
    2367          59 :                 zend_printf("%s(", function_name);
    2368          59 :                 if (Z_TYPE(arg_array) != IS_UNDEF) {
    2369          42 :                         debug_print_backtrace_args(&arg_array);
    2370          42 :                         zval_ptr_dtor(&arg_array);
    2371             :                 }
    2372          59 :                 if (filename) {
    2373          56 :                         zend_printf(") called at [%s:%d]\n", filename, lineno);
    2374             :                 } else {
    2375           3 :                         zend_execute_data *prev_call = skip;
    2376           3 :                         zend_execute_data *prev = skip->prev_execute_data;
    2377             : 
    2378           6 :                         while (prev) {
    2379           7 :                                 if (prev_call &&
    2380           3 :                                     prev_call->func &&
    2381           1 :                                         !ZEND_USER_CODE(prev_call->func->common.type)) {
    2382           1 :                                         prev = NULL;
    2383           1 :                                         break;
    2384             :                                 }
    2385           2 :                                 if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
    2386           2 :                                         zend_printf(") called at [%s:%d]\n", prev->func->op_array.filename->val, prev->opline->lineno);
    2387           2 :                                         break;
    2388             :                                 }
    2389           0 :                                 prev_call = prev;
    2390           0 :                                 prev = prev->prev_execute_data;
    2391             :                         }
    2392           3 :                         if (!prev) {
    2393           1 :                                 ZEND_PUTS(")\n");
    2394             :                         }
    2395             :                 }
    2396          59 :                 include_filename = filename;
    2397          59 :                 call = skip;
    2398          59 :                 ptr = skip->prev_execute_data;
    2399          59 :                 ++indent;
    2400             :         }
    2401             : }
    2402             : 
    2403             : /* }}} */
    2404             : 
    2405        1739 : ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit) /* {{{ */
    2406             : {
    2407             :         zend_execute_data *call, *ptr, *skip;
    2408             :         zend_object *object;
    2409        1739 :         int lineno, frameno = 0;
    2410             :         zend_function *func;
    2411             :         const char *function_name;
    2412             :         const char *filename;
    2413        1739 :         const char *include_filename = NULL;
    2414             :         zval stack_frame;
    2415             : 
    2416        1739 :         call = NULL;
    2417        1739 :         ptr = EG(current_execute_data);
    2418        1739 :         if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type)) {
    2419        1317 :                 call = ptr;
    2420        1317 :                 ptr = ptr->prev_execute_data;
    2421             :         }
    2422             : 
    2423        1739 :         if (ptr) {
    2424        1739 :                 if (skip_last) {
    2425             :                         /* skip debug_backtrace() */
    2426          47 :                         call = ptr;
    2427          47 :                         ptr = ptr->prev_execute_data;
    2428             :                 } else {
    2429             :                         /* skip "new Exception()" */
    2430        1692 :                         if (ptr->func && ZEND_USER_CODE(ptr->func->common.type) && (ptr->opline->opcode == ZEND_NEW)) {
    2431         383 :                                 call = ptr;
    2432         383 :                                 ptr = ptr->prev_execute_data;
    2433             :                         }
    2434             :                 }
    2435             :         }
    2436        1739 :         if (!call) {
    2437          37 :                 call = ptr;
    2438          37 :                 ptr = ptr->prev_execute_data;
    2439             :         }
    2440             : 
    2441        1739 :         array_init(return_value);
    2442             : 
    2443        6461 :         while (ptr && (limit == 0 || frameno < limit)) {
    2444        2983 :                 frameno++;
    2445        2983 :                 array_init(&stack_frame);
    2446             : 
    2447        2983 :                 skip = ptr;
    2448             :                 /* skip internal handler */
    2449        6460 :                 if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
    2450         922 :                     skip->prev_execute_data &&
    2451         912 :                     skip->prev_execute_data->func &&
    2452         901 :                     ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
    2453         638 :                     skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
    2454         104 :                     skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
    2455         101 :                         skip = skip->prev_execute_data;
    2456             :                 }
    2457             : 
    2458        5145 :                 if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
    2459        2162 :                         filename = skip->func->op_array.filename->val;
    2460        2162 :                         if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
    2461           2 :                                 if (EG(opline_before_exception)) {
    2462           2 :                                         lineno = EG(opline_before_exception)->lineno;
    2463             :                                 } else {
    2464           0 :                                         lineno = skip->func->op_array.line_end;
    2465             :                                 }
    2466             :                         } else {
    2467        2160 :                                 lineno = skip->opline->lineno;
    2468             :                         }
    2469        2162 :                         add_assoc_string_ex(&stack_frame, "file", sizeof("file")-1, (char*)filename);
    2470        2162 :                         add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, lineno);
    2471             : 
    2472             :                         /* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function
    2473             :                          * and debug_baktrace() might have been called by the error_handler. in this case we don't
    2474             :                          * want to pop anything of the argument-stack */
    2475             :                 } else {
    2476         821 :                         zend_execute_data *prev_call = skip;
    2477         821 :                         zend_execute_data *prev = skip->prev_execute_data;
    2478             : 
    2479        1642 :                         while (prev) {
    2480        4046 :                                 if (prev_call &&
    2481         811 :                                     prev_call->func &&
    2482         808 :                                         !ZEND_USER_CODE(prev_call->func->common.type) &&
    2483         808 :                                         !(prev_call->func->common.type == ZEND_INTERNAL_FUNCTION &&
    2484         808 :                                                 (prev_call->func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER))) {
    2485             :                                         break;
    2486             :                                 }
    2487         267 :                                 if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
    2488         534 :                                         add_assoc_str_ex(&stack_frame, "file", sizeof("file")-1, zend_string_copy(prev->func->op_array.filename));
    2489         267 :                                         add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, prev->opline->lineno);
    2490         267 :                                         break;
    2491             :                                 }
    2492           0 :                                 prev_call = prev;
    2493           0 :                                 prev = prev->prev_execute_data;
    2494             :                         }
    2495         821 :                         filename = NULL;
    2496             :                 }
    2497             : 
    2498             :                 /* $this may be passed into regular internal functions */
    2499        2983 :                 object = call ? Z_OBJ(call->This) : NULL;
    2500        9179 :                 if (object &&
    2501        2157 :                     call->func &&
    2502        2155 :                     call->func->type == ZEND_INTERNAL_FUNCTION &&
    2503        1884 :                     !call->func->common.scope) {
    2504           3 :                         object = NULL;
    2505             :                 }
    2506             : 
    2507        5963 :                 if (call && call->func) {
    2508        2980 :                         func = call->func;
    2509       11152 :                         function_name = (func->common.scope &&
    2510        2327 :                                          func->common.scope->trait_aliases) ?
    2511           2 :                                 zend_resolve_method_name(
    2512             :                                         (object ? object->ce : func->common.scope), func)->val :
    2513        2978 :                                 (func->common.function_name ?
    2514        2865 :                                         func->common.function_name->val : NULL);
    2515             :                 } else {
    2516           3 :                         func = NULL;
    2517           3 :                         function_name = NULL;
    2518             :                 }
    2519             : 
    2520        2983 :                 if (function_name) {
    2521        2867 :                         add_assoc_string_ex(&stack_frame, "function", sizeof("function")-1, (char*)function_name);
    2522             : 
    2523        2867 :                         if (object) {
    2524        2152 :                                 if (func->common.scope) {
    2525        4304 :                                         add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, zend_string_copy(func->common.scope->name));
    2526             :                                 } else {
    2527           0 :                                         add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, zend_string_copy(object->ce->name));
    2528             : 
    2529             :                                 }
    2530        2152 :                                 if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
    2531             :                                         zval zv;
    2532          26 :                                         ZVAL_OBJ(&zv, object);
    2533          26 :                                         add_assoc_zval_ex(&stack_frame, "object", sizeof("object")-1, &zv);
    2534             :                                         Z_ADDREF(zv);
    2535             :                                 }
    2536             : 
    2537        2152 :                                 add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "->");
    2538         715 :                         } else if (func->common.scope) {
    2539         350 :                                 add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, zend_string_copy(func->common.scope->name));
    2540         175 :                                 add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "::");
    2541             :                         }
    2542             : 
    2543        5722 :                         if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 &&
    2544        2855 :                                 func->type != ZEND_EVAL_CODE) {
    2545             :                                 zval args;
    2546             : 
    2547        2855 :                                 debug_backtrace_get_args(call, &args);
    2548        2855 :                                 add_assoc_zval_ex(&stack_frame, "args", sizeof("args")-1, &args);
    2549             :                         }
    2550             :                 } else {
    2551             :                         /* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
    2552         116 :                         zend_bool build_filename_arg = 1;
    2553             : 
    2554         116 :                         if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
    2555             :                                 /* can happen when calling eval from a custom sapi */
    2556           0 :                                 function_name = "unknown";
    2557           0 :                                 build_filename_arg = 0;
    2558             :                         } else
    2559         116 :                         switch (ptr->opline->extended_value) {
    2560             :                                 case ZEND_EVAL:
    2561          14 :                                         function_name = "eval";
    2562          14 :                                         build_filename_arg = 0;
    2563          14 :                                         break;
    2564             :                                 case ZEND_INCLUDE:
    2565          97 :                                         function_name = "include";
    2566          97 :                                         break;
    2567             :                                 case ZEND_REQUIRE:
    2568           5 :                                         function_name = "require";
    2569           5 :                                         break;
    2570             :                                 case ZEND_INCLUDE_ONCE:
    2571           0 :                                         function_name = "include_once";
    2572           0 :                                         break;
    2573             :                                 case ZEND_REQUIRE_ONCE:
    2574           0 :                                         function_name = "require_once";
    2575           0 :                                         break;
    2576             :                                 default:
    2577             :                                         /* this can actually happen if you use debug_backtrace() in your error_handler and
    2578             :                                          * you're in the top-scope */
    2579           0 :                                         function_name = "unknown";
    2580           0 :                                         build_filename_arg = 0;
    2581             :                                         break;
    2582             :                         }
    2583             : 
    2584         116 :                         if (build_filename_arg && include_filename) {
    2585             :                                 zval arg_array;
    2586             : 
    2587          98 :                                 array_init(&arg_array);
    2588             : 
    2589             :                                 /* include_filename always points to the last filename of the last last called-function.
    2590             :                                    if we have called include in the frame above - this is the file we have included.
    2591             :                                  */
    2592             : 
    2593          98 :                                 add_next_index_string(&arg_array, (char*)include_filename);
    2594          98 :                                 add_assoc_zval_ex(&stack_frame, "args", sizeof("args")-1, &arg_array);
    2595             :                         }
    2596             : 
    2597         116 :                         add_assoc_string_ex(&stack_frame, "function", sizeof("function")-1, (char*)function_name);
    2598             :                 }
    2599             : 
    2600        2983 :                 zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &stack_frame);
    2601             : 
    2602        2983 :                 include_filename = filename;
    2603             : 
    2604        2983 :                 call = skip;
    2605        2983 :                 ptr = skip->prev_execute_data;
    2606             :         }
    2607        1739 : }
    2608             : /* }}} */
    2609             : 
    2610             : /* {{{ proto array debug_backtrace([int options[, int limit]])
    2611             :    Return backtrace as array */
    2612          45 : ZEND_FUNCTION(debug_backtrace)
    2613             : {
    2614          45 :         zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
    2615          45 :         zend_long limit = 0;
    2616             : 
    2617          45 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
    2618           0 :                 return;
    2619             :         }
    2620             : 
    2621          45 :         zend_fetch_debug_backtrace(return_value, 1, options, limit);
    2622             : }
    2623             : /* }}} */
    2624             : 
    2625             : /* {{{ proto bool extension_loaded(string extension_name)
    2626             :    Returns true if the named extension is loaded */
    2627       18669 : ZEND_FUNCTION(extension_loaded)
    2628             : {
    2629             :         zend_string *extension_name;
    2630             :         zend_string *lcname;
    2631             : 
    2632       18669 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
    2633           0 :                 return;
    2634             :         }
    2635             : 
    2636       18669 :         lcname = zend_string_tolower(extension_name);
    2637       18669 :         if (zend_hash_exists(&module_registry, lcname)) {
    2638       18666 :                 RETVAL_TRUE;
    2639             :         } else {
    2640           3 :                 RETVAL_FALSE;
    2641             :         }
    2642             :         zend_string_release(lcname);
    2643             : }
    2644             : /* }}} */
    2645             : 
    2646             : /* {{{ proto array get_extension_funcs(string extension_name)
    2647             :    Returns an array with the names of functions belonging to the named extension */
    2648          34 : ZEND_FUNCTION(get_extension_funcs)
    2649             : {
    2650             :         zend_string *extension_name;
    2651             :         zend_string *lcname;
    2652             :         int array;
    2653             :         zend_module_entry *module;
    2654             :         zend_function *zif;
    2655             : 
    2656          34 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
    2657           7 :                 return;
    2658             :         }
    2659          27 :         if (strncasecmp(extension_name->val, "zend", sizeof("zend"))) {
    2660          25 :                 lcname = zend_string_tolower(extension_name);
    2661             :         } else {
    2662           2 :                 lcname = zend_string_init("core", sizeof("core")-1, 0);
    2663             :         }
    2664          27 :         module = zend_hash_find_ptr(&module_registry, lcname);
    2665             :         zend_string_release(lcname);
    2666          27 :         if (!module) {
    2667          20 :                 RETURN_FALSE;
    2668             :         }
    2669             : 
    2670           7 :         if (module->functions) {
    2671             :                 /* avoid BC break, if functions list is empty, will return an empty array */
    2672           7 :                 array_init(return_value);
    2673           7 :                 array = 1;
    2674             :         } else {
    2675           0 :                 array = 0;
    2676             :         }
    2677             : 
    2678       31345 :         ZEND_HASH_FOREACH_PTR(CG(function_table), zif) {
    2679       31323 :                 if (zif->common.type == ZEND_INTERNAL_FUNCTION
    2680       31323 :                         && zif->internal_function.module == module) {
    2681        2397 :                         if (!array) {
    2682           0 :                                 array_init(return_value);
    2683           0 :                                 array = 1;
    2684             :                         }
    2685        4794 :                         add_next_index_str(return_value, zend_string_copy(zif->common.function_name));
    2686             :                 }
    2687             :         } ZEND_HASH_FOREACH_END();
    2688             : 
    2689           7 :         if (!array) {
    2690           0 :                 RETURN_FALSE;
    2691             :         }
    2692             : }
    2693             : /* }}} */
    2694             : 
    2695             : /*
    2696             :  * Local variables:
    2697             :  * tab-width: 4
    2698             :  * c-basic-offset: 4
    2699             :  * indent-tabs-mode: t
    2700             :  * End:
    2701             :  */

Generated by: LCOV version 1.10

Generated at Sun, 18 Jan 2015 09:00:35 +0000 (7 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.