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: 948 1043 90.9 %
Date: 2014-10-22 Functions: 65 65 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:44 +0000 (3 days ago)

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