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

Generated by: LCOV version 1.10

Generated at Mon, 27 Jul 2015 02:32:14 +0000 (2 days ago)

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