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: 1015 1117 90.9 %
Date: 2016-05-28 Functions: 67 68 98.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sun, 29 May 2016 00:48:19 +0000 (2 days ago)

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