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

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:01 +0000 (7 days ago)

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