1999-09-20 20:24:39 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2011-01-01 10:17:06 +08:00
|
|
|
| Copyright (c) 1998-2011 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-09-20 20:24:39 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
1999-09-20 20:24:39 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-09-20 20:24:39 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 09:49:15 +08:00
|
|
|
/* $Id$ */
|
1999-09-20 20:24:39 +08:00
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_builtin_functions.h"
|
1999-09-21 05:28:37 +08:00
|
|
|
#include "zend_constants.h"
|
2002-11-20 01:51:30 +08:00
|
|
|
#include "zend_ini.h"
|
2007-02-24 10:17:47 +08:00
|
|
|
#include "zend_exceptions.h"
|
2007-08-01 06:47:25 +08:00
|
|
|
#include "zend_extensions.h"
|
2010-06-12 07:20:13 +08:00
|
|
|
#include "zend_closures.h"
|
2003-02-08 03:26:49 +08:00
|
|
|
|
2000-02-16 21:55:22 +08:00
|
|
|
#undef ZEND_TEST_EXCEPTIONS
|
|
|
|
|
1999-09-20 20:24:39 +08:00
|
|
|
static ZEND_FUNCTION(zend_version);
|
1999-09-21 15:31:24 +08:00
|
|
|
static ZEND_FUNCTION(func_num_args);
|
|
|
|
static ZEND_FUNCTION(func_get_arg);
|
|
|
|
static ZEND_FUNCTION(func_get_args);
|
2008-11-18 06:21:55 +08:00
|
|
|
static ZEND_FUNCTION(strlen);
|
1999-09-21 00:56:09 +08:00
|
|
|
static ZEND_FUNCTION(strcmp);
|
2000-02-09 01:19:43 +08:00
|
|
|
static ZEND_FUNCTION(strncmp);
|
1999-09-21 00:56:09 +08:00
|
|
|
static ZEND_FUNCTION(strcasecmp);
|
2000-07-26 19:32:15 +08:00
|
|
|
static ZEND_FUNCTION(strncasecmp);
|
1999-09-21 00:56:09 +08:00
|
|
|
static ZEND_FUNCTION(each);
|
|
|
|
static ZEND_FUNCTION(error_reporting);
|
1999-09-21 05:28:37 +08:00
|
|
|
static ZEND_FUNCTION(define);
|
|
|
|
static ZEND_FUNCTION(defined);
|
|
|
|
static ZEND_FUNCTION(get_class);
|
2007-09-29 15:28:34 +08:00
|
|
|
static ZEND_FUNCTION(get_called_class);
|
1999-09-21 05:28:37 +08:00
|
|
|
static ZEND_FUNCTION(get_parent_class);
|
|
|
|
static ZEND_FUNCTION(method_exists);
|
2005-04-08 21:33:15 +08:00
|
|
|
static ZEND_FUNCTION(property_exists);
|
1999-12-15 05:15:24 +08:00
|
|
|
static ZEND_FUNCTION(class_exists);
|
2004-08-25 08:41:43 +08:00
|
|
|
static ZEND_FUNCTION(interface_exists);
|
2011-01-10 03:57:41 +08:00
|
|
|
static ZEND_FUNCTION(trait_exists);
|
1999-12-15 05:15:24 +08:00
|
|
|
static ZEND_FUNCTION(function_exists);
|
2008-05-12 15:11:55 +08:00
|
|
|
static ZEND_FUNCTION(class_alias);
|
2002-11-21 03:44:37 +08:00
|
|
|
#if ZEND_DEBUG
|
1999-09-21 05:28:37 +08:00
|
|
|
static ZEND_FUNCTION(leak);
|
2010-11-16 01:06:27 +08:00
|
|
|
static ZEND_FUNCTION(leak_variable);
|
2000-02-15 03:08:51 +08:00
|
|
|
#ifdef ZEND_TEST_EXCEPTIONS
|
2000-02-13 09:22:11 +08:00
|
|
|
static ZEND_FUNCTION(crash);
|
2000-02-15 03:08:51 +08:00
|
|
|
#endif
|
2002-11-21 03:44:37 +08:00
|
|
|
#endif
|
2000-03-11 00:36:30 +08:00
|
|
|
static ZEND_FUNCTION(get_included_files);
|
1999-12-16 05:26:43 +08:00
|
|
|
static ZEND_FUNCTION(is_subclass_of);
|
2002-02-02 06:55:02 +08:00
|
|
|
static ZEND_FUNCTION(is_a);
|
2000-02-27 01:54:00 +08:00
|
|
|
static ZEND_FUNCTION(get_class_vars);
|
|
|
|
static ZEND_FUNCTION(get_object_vars);
|
2000-03-24 01:47:28 +08:00
|
|
|
static ZEND_FUNCTION(get_class_methods);
|
2000-06-02 20:36:54 +08:00
|
|
|
static ZEND_FUNCTION(trigger_error);
|
|
|
|
static ZEND_FUNCTION(set_error_handler);
|
2000-06-18 02:04:58 +08:00
|
|
|
static ZEND_FUNCTION(restore_error_handler);
|
2002-08-16 08:41:37 +08:00
|
|
|
static ZEND_FUNCTION(set_exception_handler);
|
|
|
|
static ZEND_FUNCTION(restore_exception_handler);
|
2000-05-02 00:22:00 +08:00
|
|
|
static ZEND_FUNCTION(get_declared_classes);
|
2010-05-06 23:18:20 +08:00
|
|
|
static ZEND_FUNCTION(get_declared_traits);
|
2003-12-08 02:54:31 +08:00
|
|
|
static ZEND_FUNCTION(get_declared_interfaces);
|
2000-10-14 23:52:24 +08:00
|
|
|
static ZEND_FUNCTION(get_defined_functions);
|
|
|
|
static ZEND_FUNCTION(get_defined_vars);
|
2000-06-05 05:30:56 +08:00
|
|
|
static ZEND_FUNCTION(create_function);
|
2000-07-15 04:00:24 +08:00
|
|
|
static ZEND_FUNCTION(get_resource_type);
|
2001-05-21 23:47:52 +08:00
|
|
|
static ZEND_FUNCTION(get_loaded_extensions);
|
|
|
|
static ZEND_FUNCTION(extension_loaded);
|
|
|
|
static ZEND_FUNCTION(get_extension_funcs);
|
|
|
|
static ZEND_FUNCTION(get_defined_constants);
|
2002-05-03 01:20:48 +08:00
|
|
|
static ZEND_FUNCTION(debug_backtrace);
|
2002-12-02 03:47:02 +08:00
|
|
|
static ZEND_FUNCTION(debug_print_backtrace);
|
2000-06-09 23:40:37 +08:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
static ZEND_FUNCTION(zend_test_func);
|
2002-09-29 03:02:21 +08:00
|
|
|
#ifdef ZTS
|
2002-09-18 22:08:07 +08:00
|
|
|
static ZEND_FUNCTION(zend_thread_id);
|
2000-06-09 23:40:37 +08:00
|
|
|
#endif
|
2002-09-28 23:12:41 +08:00
|
|
|
#endif
|
2008-01-22 17:27:48 +08:00
|
|
|
static ZEND_FUNCTION(gc_collect_cycles);
|
|
|
|
static ZEND_FUNCTION(gc_enabled);
|
|
|
|
static ZEND_FUNCTION(gc_enable);
|
|
|
|
static ZEND_FUNCTION(gc_disable);
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2008-07-06 07:30:22 +08:00
|
|
|
/* {{{ arginfo */
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_zend__void, 0)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, arg_num)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_strlen, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, str)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_strcmp, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, str1)
|
|
|
|
ZEND_ARG_INFO(0, str2)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3)
|
|
|
|
ZEND_ARG_INFO(0, str1)
|
|
|
|
ZEND_ARG_INFO(0, str2)
|
|
|
|
ZEND_ARG_INFO(0, len)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_each, 0, 0, 1)
|
2008-07-06 09:57:39 +08:00
|
|
|
ZEND_ARG_INFO(1, arr)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2008-12-31 02:55:16 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_ARG_INFO(0, new_error_level)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_define, 0, 0, 3)
|
|
|
|
ZEND_ARG_INFO(0, constant_name)
|
|
|
|
ZEND_ARG_INFO(0, value)
|
|
|
|
ZEND_ARG_INFO(0, case_insensitive)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_defined, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, constant_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class, 0, 0, 0)
|
|
|
|
ZEND_ARG_INFO(0, object)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_is_subclass_of, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, object)
|
|
|
|
ZEND_ARG_INFO(0, class_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_vars, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, class_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_object_vars, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, obj)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, class)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_method_exists, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, object)
|
|
|
|
ZEND_ARG_INFO(0, method)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_property_exists, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, object_or_class)
|
|
|
|
ZEND_ARG_INFO(0, property_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_exists, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, classname)
|
|
|
|
ZEND_ARG_INFO(0, autoload)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2011-01-10 03:57:41 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_trait_exists, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, traitname)
|
|
|
|
ZEND_ARG_INFO(0, autoload)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_function_exists, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, function_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, user_class_name)
|
|
|
|
ZEND_ARG_INFO(0, alias_name)
|
|
|
|
ZEND_ARG_INFO(0, autoload)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2010-11-16 01:06:27 +08:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, variable)
|
|
|
|
ZEND_ARG_INFO(0, leak_data)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
#endif
|
|
|
|
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
|
2010-05-02 02:54:49 +08:00
|
|
|
ZEND_ARG_INFO(0, message)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_ARG_INFO(0, error_type)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, error_handler)
|
|
|
|
ZEND_ARG_INFO(0, error_types)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, exception_handler)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2)
|
|
|
|
ZEND_ARG_INFO(0, args)
|
|
|
|
ZEND_ARG_INFO(0, code)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, res)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_loaded_extensions, 0, 0, 0)
|
|
|
|
ZEND_ARG_INFO(0, zend_extensions)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_constants, 0, 0, 0)
|
|
|
|
ZEND_ARG_INFO(0, categorize)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_backtrace, 0, 0, 0)
|
2011-01-17 04:39:22 +08:00
|
|
|
ZEND_ARG_INFO(0, options)
|
2011-04-09 17:52:24 +08:00
|
|
|
ZEND_ARG_INFO(0, limit)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_print_backtrace, 0, 0, 0)
|
|
|
|
ZEND_ARG_INFO(0, options)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, extension_name)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
/* }}} */
|
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
|
|
|
|
2008-12-31 02:17:44 +08:00
|
|
|
static const zend_function_entry builtin_functions[] = { /* {{{ */
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(zend_version, arginfo_zend__void)
|
|
|
|
ZEND_FE(func_num_args, arginfo_zend__void)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(func_get_arg, arginfo_func_get_arg)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(func_get_args, arginfo_zend__void)
|
|
|
|
ZEND_FE(strlen, arginfo_strlen)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(strcmp, arginfo_strcmp)
|
|
|
|
ZEND_FE(strncmp, arginfo_strncmp)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(strcasecmp, arginfo_strcmp)
|
|
|
|
ZEND_FE(strncasecmp, arginfo_strncmp)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(each, arginfo_each)
|
|
|
|
ZEND_FE(error_reporting, arginfo_error_reporting)
|
|
|
|
ZEND_FE(define, arginfo_define)
|
|
|
|
ZEND_FE(defined, arginfo_defined)
|
|
|
|
ZEND_FE(get_class, arginfo_get_class)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(get_called_class, arginfo_zend__void)
|
|
|
|
ZEND_FE(get_parent_class, arginfo_get_class)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(method_exists, arginfo_method_exists)
|
|
|
|
ZEND_FE(property_exists, arginfo_property_exists)
|
|
|
|
ZEND_FE(class_exists, arginfo_class_exists)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(interface_exists, arginfo_class_exists)
|
2011-01-10 03:57:41 +08:00
|
|
|
ZEND_FE(trait_exists, arginfo_trait_exists)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(function_exists, arginfo_function_exists)
|
|
|
|
ZEND_FE(class_alias, arginfo_class_alias)
|
2002-11-21 03:44:37 +08:00
|
|
|
#if ZEND_DEBUG
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FE(leak, NULL)
|
2010-11-16 01:06:27 +08:00
|
|
|
ZEND_FE(leak_variable, arginfo_leak_variable)
|
2000-02-13 09:22:11 +08:00
|
|
|
#ifdef ZEND_TEST_EXCEPTIONS
|
|
|
|
ZEND_FE(crash, NULL)
|
2002-11-21 03:44:37 +08:00
|
|
|
#endif
|
2000-02-13 09:22:11 +08:00
|
|
|
#endif
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(get_included_files, arginfo_zend__void)
|
|
|
|
ZEND_FALIAS(get_required_files, get_included_files, arginfo_zend__void)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(is_subclass_of, arginfo_is_subclass_of)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(is_a, arginfo_is_subclass_of)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(get_class_vars, arginfo_get_class_vars)
|
|
|
|
ZEND_FE(get_object_vars, arginfo_get_object_vars)
|
|
|
|
ZEND_FE(get_class_methods, arginfo_get_class_methods)
|
|
|
|
ZEND_FE(trigger_error, arginfo_trigger_error)
|
|
|
|
ZEND_FALIAS(user_error, trigger_error, arginfo_trigger_error)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(set_error_handler, arginfo_set_error_handler)
|
|
|
|
ZEND_FE(restore_error_handler, arginfo_zend__void)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(set_exception_handler, arginfo_set_exception_handler)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(restore_exception_handler, arginfo_zend__void)
|
|
|
|
ZEND_FE(get_declared_classes, arginfo_zend__void)
|
2010-05-06 23:18:20 +08:00
|
|
|
ZEND_FE(get_declared_traits, arginfo_zend__void)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(get_declared_interfaces, arginfo_zend__void)
|
|
|
|
ZEND_FE(get_defined_functions, arginfo_zend__void)
|
|
|
|
ZEND_FE(get_defined_vars, arginfo_zend__void)
|
|
|
|
ZEND_FE(create_function, arginfo_create_function)
|
|
|
|
ZEND_FE(get_resource_type, arginfo_get_resource_type)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions)
|
|
|
|
ZEND_FE(extension_loaded, arginfo_extension_loaded)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(get_extension_funcs, arginfo_extension_loaded)
|
2008-07-06 07:30:22 +08:00
|
|
|
ZEND_FE(get_defined_constants, arginfo_get_defined_constants)
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(debug_backtrace, arginfo_debug_backtrace)
|
2011-04-09 17:52:24 +08:00
|
|
|
ZEND_FE(debug_print_backtrace, arginfo_debug_print_backtrace)
|
2000-06-09 23:40:37 +08:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
ZEND_FE(zend_test_func, NULL)
|
2002-09-29 03:02:21 +08:00
|
|
|
#ifdef ZTS
|
2002-09-18 22:08:07 +08:00
|
|
|
ZEND_FE(zend_thread_id, NULL)
|
2002-09-28 23:12:41 +08:00
|
|
|
#endif
|
2000-06-09 23:40:37 +08:00
|
|
|
#endif
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FE(gc_collect_cycles, arginfo_zend__void)
|
|
|
|
ZEND_FE(gc_enabled, arginfo_zend__void)
|
|
|
|
ZEND_FE(gc_enable, arginfo_zend__void)
|
|
|
|
ZEND_FE(gc_disable, arginfo_zend__void)
|
2011-07-25 19:50:10 +08:00
|
|
|
ZEND_FE_END
|
1999-09-20 20:24:39 +08:00
|
|
|
};
|
2008-12-31 02:17:44 +08:00
|
|
|
/* }}} */
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2008-12-31 20:26:33 +08:00
|
|
|
ZEND_MINIT_FUNCTION(core) { /* {{{ */
|
|
|
|
zend_class_entry class_entry;
|
|
|
|
|
|
|
|
INIT_CLASS_ENTRY(class_entry, "stdClass", NULL);
|
|
|
|
zend_standard_class_def = zend_register_internal_class(&class_entry TSRMLS_CC);
|
|
|
|
|
2008-12-31 21:25:21 +08:00
|
|
|
zend_register_default_classes(TSRMLS_C);
|
|
|
|
|
2008-12-31 20:26:33 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2008-12-31 02:17:44 +08:00
|
|
|
zend_module_entry zend_builtin_module = { /* {{{ */
|
|
|
|
STANDARD_MODULE_HEADER,
|
2008-12-31 04:15:28 +08:00
|
|
|
"Core",
|
2008-12-31 02:17:44 +08:00
|
|
|
builtin_functions,
|
2008-12-31 20:26:33 +08:00
|
|
|
ZEND_MINIT(core),
|
2008-12-31 02:17:44 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
ZEND_VERSION,
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
/* }}} */
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2008-12-31 02:17:44 +08:00
|
|
|
int zend_startup_builtin_functions(TSRMLS_D) /* {{{ */
|
1999-09-20 20:24:39 +08:00
|
|
|
{
|
2008-12-31 04:15:28 +08:00
|
|
|
zend_builtin_module.module_number = 0;
|
|
|
|
zend_builtin_module.type = MODULE_PERSISTENT;
|
|
|
|
return (EG(current_module) = zend_register_module_ex(&zend_builtin_module TSRMLS_CC)) == NULL ? FAILURE : SUCCESS;
|
1999-09-20 20:24:39 +08:00
|
|
|
}
|
2008-12-31 02:17:44 +08:00
|
|
|
/* }}} */
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
/* {{{ proto string zend_version(void)
|
|
|
|
Get the version of the Zend Engine */
|
1999-09-20 20:24:39 +08:00
|
|
|
ZEND_FUNCTION(zend_version)
|
|
|
|
{
|
|
|
|
RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1, 1);
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-09-20 21:00:35 +08:00
|
|
|
|
2008-01-22 17:27:48 +08:00
|
|
|
/* {{{ proto int gc_collect_cycles(void)
|
|
|
|
Forces collection of any existing garbage cycles.
|
|
|
|
Returns number of freed zvals */
|
|
|
|
ZEND_FUNCTION(gc_collect_cycles)
|
|
|
|
{
|
|
|
|
RETURN_LONG(gc_collect_cycles(TSRMLS_C));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void gc_enabled(void)
|
|
|
|
Returns status of the circular reference collector */
|
|
|
|
ZEND_FUNCTION(gc_enabled)
|
|
|
|
{
|
|
|
|
RETURN_BOOL(GC_G(gc_enabled));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void gc_enable(void)
|
|
|
|
Activates the circular reference collector */
|
|
|
|
ZEND_FUNCTION(gc_enable)
|
|
|
|
{
|
|
|
|
zend_alter_ini_entry("zend.enable_gc", sizeof("zend.enable_gc"), "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void gc_disable(void)
|
|
|
|
Deactivates the circular reference collector */
|
|
|
|
ZEND_FUNCTION(gc_disable)
|
|
|
|
{
|
|
|
|
zend_alter_ini_entry("zend.enable_gc", sizeof("zend.enable_gc"), "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-09-20 21:00:35 +08:00
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
/* {{{ proto int func_num_args(void)
|
|
|
|
Get the number of arguments that were passed to the function */
|
1999-09-21 15:31:24 +08:00
|
|
|
ZEND_FUNCTION(func_num_args)
|
1999-09-20 21:00:35 +08:00
|
|
|
{
|
2008-01-24 17:41:39 +08:00
|
|
|
zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
|
1999-09-20 21:00:35 +08:00
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
if (ex && ex->function_state.arguments) {
|
|
|
|
RETURN_LONG((long)(zend_uintptr_t)*(ex->function_state.arguments));
|
1999-09-20 21:00:35 +08:00
|
|
|
} else {
|
1999-09-21 15:31:24 +08:00
|
|
|
zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context");
|
1999-09-20 21:00:35 +08:00
|
|
|
RETURN_LONG(-1);
|
|
|
|
}
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-09-20 21:00:35 +08:00
|
|
|
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
/* {{{ proto mixed func_get_arg(int arg_num)
|
|
|
|
Get the $arg_num'th argument that was passed to the function */
|
1999-09-21 15:31:24 +08:00
|
|
|
ZEND_FUNCTION(func_get_arg)
|
1999-09-20 21:00:35 +08:00
|
|
|
{
|
|
|
|
void **p;
|
|
|
|
int arg_count;
|
|
|
|
zval *arg;
|
|
|
|
long requested_offset;
|
2008-01-24 17:41:39 +08:00
|
|
|
zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
|
1999-09-20 21:00:35 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &requested_offset) == FAILURE) {
|
|
|
|
return;
|
1999-09-20 21:00:35 +08:00
|
|
|
}
|
|
|
|
|
2002-05-08 22:10:30 +08:00
|
|
|
if (requested_offset < 0) {
|
|
|
|
zend_error(E_WARNING, "func_get_arg(): The argument number should be >= 0");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
if (!ex || !ex->function_state.arguments) {
|
1999-09-21 15:31:24 +08:00
|
|
|
zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
|
1999-09-20 21:00:35 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
p = ex->function_state.arguments;
|
|
|
|
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_arg(); */
|
|
|
|
|
|
|
|
if (requested_offset >= arg_count) {
|
2003-08-29 00:41:20 +08:00
|
|
|
zend_error(E_WARNING, "func_get_arg(): Argument %ld not passed to function", requested_offset);
|
1999-09-20 21:00:35 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
arg = *(p-(arg_count-requested_offset));
|
|
|
|
*return_value = *arg;
|
|
|
|
zval_copy_ctor(return_value);
|
2005-08-18 23:13:45 +08:00
|
|
|
INIT_PZVAL(return_value);
|
1999-09-20 21:00:35 +08:00
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-09-20 21:00:35 +08:00
|
|
|
|
1999-09-21 15:31:24 +08:00
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
/* {{{ proto array func_get_args()
|
|
|
|
Get an array of the arguments that were passed to the function */
|
1999-09-21 15:31:24 +08:00
|
|
|
ZEND_FUNCTION(func_get_args)
|
|
|
|
{
|
|
|
|
void **p;
|
|
|
|
int arg_count;
|
|
|
|
int i;
|
2008-01-24 17:41:39 +08:00
|
|
|
zend_execute_data *ex = EG(current_execute_data)->prev_execute_data;
|
1999-09-21 15:31:24 +08:00
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
if (!ex || !ex->function_state.arguments) {
|
1999-09-21 15:31:24 +08:00
|
|
|
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
p = ex->function_state.arguments;
|
|
|
|
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_args(); */
|
1999-09-21 15:31:24 +08:00
|
|
|
|
2008-05-27 18:29:33 +08:00
|
|
|
array_init_size(return_value, arg_count);
|
1999-09-21 15:31:24 +08:00
|
|
|
for (i=0; i<arg_count; i++) {
|
|
|
|
zval *element;
|
|
|
|
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(element);
|
1999-09-21 15:31:24 +08:00
|
|
|
*element = **((zval **) (p-(arg_count-i)));
|
|
|
|
zval_copy_ctor(element);
|
|
|
|
INIT_PZVAL(element);
|
|
|
|
zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL);
|
|
|
|
}
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-09-21 15:31:24 +08:00
|
|
|
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
/* {{{ proto int strlen(string str)
|
|
|
|
Get string length */
|
2008-11-18 06:21:55 +08:00
|
|
|
ZEND_FUNCTION(strlen)
|
1999-09-21 00:56:09 +08:00
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *s1;
|
|
|
|
int s1_len;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s1, &s1_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
|
|
|
RETVAL_LONG(s1_len);
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
/* {{{ proto int strcmp(string str1, string str2)
|
|
|
|
Binary safe string comparison */
|
|
|
|
ZEND_FUNCTION(strcmp)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *s1, *s2;
|
|
|
|
int s1_len, s2_len;
|
1999-09-21 00:56:09 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
|
|
|
RETURN_LONG(zend_binary_strcmp(s1, s1_len, s2, s2_len));
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2000-02-09 01:19:43 +08:00
|
|
|
/* {{{ proto int strncmp(string str1, string str2, int len)
|
|
|
|
Binary safe string comparison */
|
|
|
|
ZEND_FUNCTION(strncmp)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *s1, *s2;
|
|
|
|
int s1_len, s2_len;
|
|
|
|
long len;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &s1, &s1_len, &s2, &s2_len, &len) == FAILURE) {
|
|
|
|
return;
|
2000-02-09 01:19:43 +08:00
|
|
|
}
|
2006-04-05 19:36:13 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (len < 0) {
|
2006-04-05 19:36:13 +08:00
|
|
|
zend_error(E_WARNING, "Length must be greater than or equal to 0");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
|
|
|
RETURN_LONG(zend_binary_strncmp(s1, s1_len, s2, s2_len, len));
|
2000-02-09 01:19:43 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
/* {{{ proto int strcasecmp(string str1, string str2)
|
|
|
|
Binary safe case-insensitive string comparison */
|
|
|
|
ZEND_FUNCTION(strcasecmp)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *s1, *s2;
|
|
|
|
int s1_len, s2_len;
|
1999-09-21 00:56:09 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
|
|
|
RETURN_LONG(zend_binary_strcasecmp(s1, s1_len, s2, s2_len));
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2000-07-26 19:32:15 +08:00
|
|
|
/* {{{ proto int strncasecmp(string str1, string str2, int len)
|
|
|
|
Binary safe string comparison */
|
|
|
|
ZEND_FUNCTION(strncasecmp)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *s1, *s2;
|
|
|
|
int s1_len, s2_len;
|
|
|
|
long len;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &s1, &s1_len, &s2, &s2_len, &len) == FAILURE) {
|
|
|
|
return;
|
2000-07-26 19:32:15 +08:00
|
|
|
}
|
2006-04-05 19:36:13 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (len < 0) {
|
2006-04-05 19:36:13 +08:00
|
|
|
zend_error(E_WARNING, "Length must be greater than or equal to 0");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
RETURN_LONG(zend_binary_strncasecmp(s1, s1_len, s2, s2_len, len));
|
2000-07-26 19:32:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
|
|
|
/* {{{ proto array each(array arr)
|
|
|
|
Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element */
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FUNCTION(each)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *array, *entry, **entry_ptr, *tmp;
|
1999-09-21 00:56:09 +08:00
|
|
|
char *string_key;
|
2003-07-24 21:06:25 +08:00
|
|
|
uint string_key_len;
|
1999-09-21 00:56:09 +08:00
|
|
|
ulong num_key;
|
|
|
|
zval **inserted_pointer;
|
|
|
|
HashTable *target_hash;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &array) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
2001-07-29 02:35:22 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
target_hash = HASH_OF(array);
|
1999-09-21 00:56:09 +08:00
|
|
|
if (!target_hash) {
|
|
|
|
zend_error(E_WARNING,"Variable passed to each() is not an array or object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (zend_hash_get_current_data(target_hash, (void **) &entry_ptr)==FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
array_init(return_value);
|
|
|
|
entry = *entry_ptr;
|
|
|
|
|
|
|
|
/* add value elements */
|
2007-10-07 13:22:07 +08:00
|
|
|
if (Z_ISREF_P(entry)) {
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-09-21 00:56:09 +08:00
|
|
|
*tmp = *entry;
|
|
|
|
zval_copy_ctor(tmp);
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_UNSET_ISREF_P(tmp);
|
|
|
|
Z_SET_REFCOUNT_P(tmp, 0);
|
1999-09-21 00:56:09 +08:00
|
|
|
entry=tmp;
|
|
|
|
}
|
|
|
|
zend_hash_index_update(return_value->value.ht, 1, &entry, sizeof(zval *), NULL);
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_P(entry);
|
2000-03-24 19:12:30 +08:00
|
|
|
zend_hash_update(return_value->value.ht, "value", sizeof("value"), &entry, sizeof(zval *), NULL);
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_P(entry);
|
1999-09-21 00:56:09 +08:00
|
|
|
|
|
|
|
/* add the key elements */
|
2003-07-24 21:06:25 +08:00
|
|
|
switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_key_len, &num_key, 1, NULL)) {
|
1999-09-21 00:56:09 +08:00
|
|
|
case HASH_KEY_IS_STRING:
|
2003-07-24 21:06:25 +08:00
|
|
|
add_get_index_stringl(return_value, 0, string_key, string_key_len-1, (void **) &inserted_pointer, 0);
|
1999-09-21 00:56:09 +08:00
|
|
|
break;
|
|
|
|
case HASH_KEY_IS_LONG:
|
2001-08-11 23:56:40 +08:00
|
|
|
add_get_index_long(return_value, 0, num_key, (void **) &inserted_pointer);
|
1999-09-21 00:56:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
zend_hash_update(return_value->value.ht, "key", sizeof("key"), inserted_pointer, sizeof(zval *), NULL);
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_PP(inserted_pointer);
|
1999-09-21 00:56:09 +08:00
|
|
|
zend_hash_move_forward(target_hash);
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
|
2008-12-31 02:55:16 +08:00
|
|
|
/* {{{ proto int error_reporting([int new_error_level])
|
2001-12-05 01:58:32 +08:00
|
|
|
Return the current error_reporting level, and if an argument was passed - change to the new level */
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FUNCTION(error_reporting)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *err;
|
|
|
|
int err_len;
|
1999-09-21 00:56:09 +08:00
|
|
|
int old_error_reporting;
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &err, &err_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
old_error_reporting = EG(error_reporting);
|
2008-06-19 07:38:37 +08:00
|
|
|
if(ZEND_NUM_ARGS() != 0) {
|
|
|
|
zend_alter_ini_entry("error_reporting", sizeof("error_reporting"), err, err_len, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
2000-06-30 19:45:32 +08:00
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
RETVAL_LONG(old_error_reporting);
|
1999-09-21 01:01:38 +08:00
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
|
|
|
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
/* {{{ proto bool define(string constant_name, mixed value, boolean case_insensitive=false)
|
2001-12-05 01:58:32 +08:00
|
|
|
Define a new constant */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(define)
|
|
|
|
{
|
2008-10-23 07:28:34 +08:00
|
|
|
char *name;
|
2008-06-19 07:38:37 +08:00
|
|
|
int name_len;
|
2008-06-19 19:27:41 +08:00
|
|
|
zval *val;
|
|
|
|
zval *val_free = NULL;
|
2008-06-19 07:38:37 +08:00
|
|
|
zend_bool non_cs = 0;
|
|
|
|
int case_sensitive = CONST_CS;
|
1999-09-21 05:28:37 +08:00
|
|
|
zend_constant c;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|b", &name, &name_len, &val, &non_cs) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(non_cs) {
|
|
|
|
case_sensitive = 0;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
2000-07-28 17:44:46 +08:00
|
|
|
|
2009-06-08 09:26:03 +08:00
|
|
|
/* class constant, check if there is name and make sure class is valid & exists */
|
2009-12-31 03:15:11 +08:00
|
|
|
if (zend_memnstr(name, "::", sizeof("::") - 1, name + name_len)) {
|
|
|
|
zend_error(E_WARNING, "Class constants cannot be defined or redefined");
|
|
|
|
RETURN_FALSE;
|
2009-06-08 09:26:03 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 06:45:11 +08:00
|
|
|
repeat:
|
2008-06-19 07:38:37 +08:00
|
|
|
switch (Z_TYPE_P(val)) {
|
1999-09-21 05:28:37 +08:00
|
|
|
case IS_LONG:
|
|
|
|
case IS_DOUBLE:
|
|
|
|
case IS_STRING:
|
|
|
|
case IS_BOOL:
|
|
|
|
case IS_RESOURCE:
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
1999-09-21 05:28:37 +08:00
|
|
|
break;
|
2006-07-10 06:45:11 +08:00
|
|
|
case IS_OBJECT:
|
|
|
|
if (!val_free) {
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_OBJ_HT_P(val)->get) {
|
|
|
|
val_free = val = Z_OBJ_HT_P(val)->get(val TSRMLS_CC);
|
2006-07-10 06:45:11 +08:00
|
|
|
goto repeat;
|
2008-06-19 07:38:37 +08:00
|
|
|
} else if (Z_OBJ_HT_P(val)->cast_object) {
|
2006-07-10 06:45:11 +08:00
|
|
|
ALLOC_INIT_ZVAL(val_free);
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_OBJ_HT_P(val)->cast_object(val, val_free, IS_STRING TSRMLS_CC) == SUCCESS) {
|
|
|
|
val = val_free;
|
2006-07-10 06:45:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no break */
|
1999-09-21 05:28:37 +08:00
|
|
|
default:
|
|
|
|
zend_error(E_WARNING,"Constants may only evaluate to scalar values");
|
2006-07-10 06:45:11 +08:00
|
|
|
if (val_free) {
|
|
|
|
zval_ptr_dtor(&val_free);
|
|
|
|
}
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
c.value = *val;
|
1999-09-21 05:28:37 +08:00
|
|
|
zval_copy_ctor(&c.value);
|
2006-07-10 06:45:11 +08:00
|
|
|
if (val_free) {
|
|
|
|
zval_ptr_dtor(&val_free);
|
|
|
|
}
|
2000-03-18 22:45:29 +08:00
|
|
|
c.flags = case_sensitive; /* non persistent */
|
2010-04-20 19:05:54 +08:00
|
|
|
c.name = IS_INTERNED(name) ? name : zend_strndup(name, name_len);
|
2008-06-19 07:38:37 +08:00
|
|
|
c.name_len = name_len+1;
|
2003-08-23 02:50:12 +08:00
|
|
|
c.module_number = PHP_USER_CONSTANT;
|
2001-07-27 18:10:39 +08:00
|
|
|
if (zend_register_constant(&c TSRMLS_CC) == SUCCESS) {
|
2002-05-13 16:41:55 +08:00
|
|
|
RETURN_TRUE;
|
2000-07-28 17:44:46 +08:00
|
|
|
} else {
|
2002-05-13 16:41:55 +08:00
|
|
|
RETURN_FALSE;
|
2000-07-28 17:44:46 +08:00
|
|
|
}
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-09-21 05:28:37 +08:00
|
|
|
|
|
|
|
|
2002-03-02 21:26:37 +08:00
|
|
|
/* {{{ proto bool defined(string constant_name)
|
2001-12-05 01:58:32 +08:00
|
|
|
Check whether a constant exists */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(defined)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *name;
|
|
|
|
int name_len;
|
1999-09-21 05:28:37 +08:00
|
|
|
zval c;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_get_constant_ex(name, name_len, &c, NULL, ZEND_FETCH_CLASS_SILENT TSRMLS_CC)) {
|
1999-09-21 05:28:37 +08:00
|
|
|
zval_dtor(&c);
|
2004-03-01 16:07:25 +08:00
|
|
|
RETURN_TRUE;
|
1999-09-21 05:28:37 +08:00
|
|
|
} else {
|
2004-03-01 16:07:25 +08:00
|
|
|
RETURN_FALSE;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
|
|
|
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2004-03-15 06:40:25 +08:00
|
|
|
/* {{{ proto string get_class([object object])
|
2000-02-28 02:41:19 +08:00
|
|
|
Retrieves the class name */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(get_class)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *obj = NULL;
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *name = "";
|
2003-04-22 01:01:34 +08:00
|
|
|
zend_uint name_len = 0;
|
2005-06-28 02:13:13 +08:00
|
|
|
int dup;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2009-08-06 19:02:25 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|o!", &obj) == FAILURE) {
|
2009-03-16 17:51:32 +08:00
|
|
|
RETURN_FALSE;
|
2008-06-19 07:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!obj) {
|
2004-03-15 06:40:25 +08:00
|
|
|
if (EG(scope)) {
|
|
|
|
RETURN_STRINGL(EG(scope)->name, EG(scope)->name_length, 1);
|
|
|
|
} else {
|
2006-06-28 03:58:43 +08:00
|
|
|
zend_error(E_WARNING, "get_class() called without object from outside a class");
|
|
|
|
RETURN_FALSE;
|
2004-03-15 06:40:25 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-29 02:35:22 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
dup = zend_get_object_classname(obj, &name, &name_len TSRMLS_CC);
|
2002-04-22 22:22:27 +08:00
|
|
|
|
2005-06-28 02:13:13 +08:00
|
|
|
RETURN_STRINGL(name, name_len, dup);
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2007-09-29 15:28:34 +08:00
|
|
|
/* {{{ proto string get_called_class()
|
|
|
|
Retrieves the "Late Static Binding" class name */
|
|
|
|
ZEND_FUNCTION(get_called_class)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EG(called_scope)) {
|
|
|
|
RETURN_STRINGL(EG(called_scope)->name, EG(called_scope)->name_length, 1);
|
2009-01-11 03:15:42 +08:00
|
|
|
} else if (!EG(scope)) {
|
2008-06-19 07:38:37 +08:00
|
|
|
zend_error(E_WARNING, "get_called_class() called from outside a class");
|
2007-09-29 15:28:34 +08:00
|
|
|
}
|
2009-01-11 03:15:42 +08:00
|
|
|
RETURN_FALSE;
|
2007-09-29 15:28:34 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2004-10-14 15:26:04 +08:00
|
|
|
/* {{{ proto string get_parent_class([mixed object])
|
|
|
|
Retrieves the parent class name for object or class or current scope. */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(get_parent_class)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *arg;
|
2001-03-27 03:03:06 +08:00
|
|
|
zend_class_entry *ce = NULL;
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *name;
|
2003-04-22 01:01:34 +08:00
|
|
|
zend_uint name_length;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-14 15:26:04 +08:00
|
|
|
if (!ZEND_NUM_ARGS()) {
|
|
|
|
ce = EG(scope);
|
|
|
|
if (ce && ce->parent) {
|
|
|
|
RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1);
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-27 03:03:06 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(arg) == IS_OBJECT) {
|
|
|
|
if (Z_OBJ_HT_P(arg)->get_class_name
|
|
|
|
&& Z_OBJ_HT_P(arg)->get_class_name(arg, &name, &name_length, 1 TSRMLS_CC) == SUCCESS) {
|
2003-07-03 16:00:10 +08:00
|
|
|
RETURN_STRINGL(name, name_length, 0);
|
|
|
|
} else {
|
2008-06-19 07:38:37 +08:00
|
|
|
ce = zend_get_class_entry(arg TSRMLS_CC);
|
2003-07-03 16:00:10 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
} else if (Z_TYPE_P(arg) == IS_STRING) {
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_class_entry **pce;
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_lookup_class(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &pce TSRMLS_CC) == SUCCESS) {
|
2002-03-12 18:08:47 +08:00
|
|
|
ce = *pce;
|
|
|
|
}
|
2001-03-27 03:03:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ce && ce->parent) {
|
2003-06-04 16:16:55 +08:00
|
|
|
RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1);
|
2001-03-27 03:03:06 +08:00
|
|
|
} else {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-12-16 05:26:43 +08:00
|
|
|
|
2002-02-07 22:08:43 +08:00
|
|
|
|
2002-02-02 06:55:02 +08:00
|
|
|
static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
|
1999-12-16 05:26:43 +08:00
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *obj;
|
|
|
|
char *class_name;
|
|
|
|
int class_name_len;
|
2003-03-05 19:14:44 +08:00
|
|
|
zend_class_entry *instance_ce;
|
|
|
|
zend_class_entry **ce;
|
2011-11-09 13:27:45 +08:00
|
|
|
zend_bool allow_string = only_subclass;
|
2003-03-05 19:14:44 +08:00
|
|
|
zend_bool retval;
|
1999-12-16 05:26:43 +08:00
|
|
|
|
2011-11-09 13:27:45 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|b", &obj, &class_name, &class_name_len, &allow_string) == FAILURE) {
|
2008-06-19 07:38:37 +08:00
|
|
|
return;
|
1999-12-16 05:26:43 +08:00
|
|
|
}
|
2011-11-09 13:27:45 +08:00
|
|
|
/*
|
|
|
|
* allow_string - is_a default is no, is_subclass_of is yes.
|
|
|
|
* if it's allowed, then the autoloader will be called if the class does not exist.
|
|
|
|
* default behaviour is different, as 'is_a' used to be used to test mixed return values
|
|
|
|
* and there is no easy way to deprecate this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (allow_string && Z_TYPE_P(obj) == IS_STRING) {
|
2004-10-27 07:25:05 +08:00
|
|
|
zend_class_entry **the_ce;
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) {
|
2004-10-27 07:25:05 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
instance_ce = *the_ce;
|
2011-07-04 22:55:39 +08:00
|
|
|
} else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) {
|
|
|
|
instance_ce = Z_OBJCE_P(obj);
|
2004-10-27 07:25:05 +08:00
|
|
|
} else {
|
2002-02-07 22:08:43 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-16 05:26:43 +08:00
|
|
|
|
2010-04-20 18:57:45 +08:00
|
|
|
if (zend_lookup_class_ex(class_name, class_name_len, NULL, 0, &ce TSRMLS_CC) == FAILURE) {
|
2003-03-05 19:14:44 +08:00
|
|
|
retval = 0;
|
|
|
|
} else {
|
2011-07-04 22:55:39 +08:00
|
|
|
if (only_subclass && instance_ce == *ce) {
|
2003-03-05 19:14:44 +08:00
|
|
|
retval = 0;
|
2011-07-04 22:55:39 +08:00
|
|
|
} else {
|
|
|
|
retval = instanceof_function(instance_ce, *ce TSRMLS_CC);
|
1999-12-16 05:26:43 +08:00
|
|
|
}
|
1999-12-16 06:37:05 +08:00
|
|
|
}
|
2003-03-05 19:14:44 +08:00
|
|
|
|
|
|
|
RETURN_BOOL(retval);
|
1999-12-16 05:26:43 +08:00
|
|
|
}
|
2002-07-05 10:34:54 +08:00
|
|
|
|
2002-02-02 06:55:02 +08:00
|
|
|
|
2011-11-09 13:27:45 +08:00
|
|
|
/* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string=true])
|
2003-06-09 08:15:11 +08:00
|
|
|
Returns true if the object has this class as one of its parents */
|
2002-02-02 06:55:02 +08:00
|
|
|
ZEND_FUNCTION(is_subclass_of)
|
|
|
|
{
|
|
|
|
is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2011-11-09 13:27:45 +08:00
|
|
|
/* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string=false])
|
|
|
|
Returns true if the first argument is an object and is this class or has this class as one of its parents, */
|
2002-02-02 06:55:02 +08:00
|
|
|
ZEND_FUNCTION(is_a)
|
|
|
|
{
|
|
|
|
is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
|
|
|
}
|
1999-12-16 05:26:43 +08:00
|
|
|
/* }}} */
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2004-10-13 06:19:43 +08:00
|
|
|
/* {{{ add_class_vars */
|
2010-05-24 22:11:39 +08:00
|
|
|
static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC)
|
2004-10-13 06:19:43 +08:00
|
|
|
{
|
2010-05-24 22:11:39 +08:00
|
|
|
HashPosition pos;
|
|
|
|
zend_property_info *prop_info;
|
|
|
|
zval *prop, *prop_copy;
|
|
|
|
char *key;
|
|
|
|
uint key_len;
|
|
|
|
ulong num_index;
|
|
|
|
|
|
|
|
zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
|
|
|
|
while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS) {
|
|
|
|
zend_hash_get_current_key_ex(&ce->properties_info, &key, &key_len, &num_index, 0, &pos);
|
|
|
|
zend_hash_move_forward_ex(&ce->properties_info, &pos);
|
|
|
|
if (((prop_info->flags & ZEND_ACC_SHADOW) &&
|
|
|
|
prop_info->ce != EG(scope)) ||
|
|
|
|
((prop_info->flags & ZEND_ACC_PROTECTED) &&
|
|
|
|
!zend_check_protected(prop_info->ce, EG(scope))) ||
|
|
|
|
((prop_info->flags & ZEND_ACC_PRIVATE) &&
|
|
|
|
ce != EG(scope) &&
|
|
|
|
prop_info->ce != EG(scope))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prop = NULL;
|
|
|
|
if (prop_info->offset >= 0) {
|
|
|
|
if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
|
|
|
|
prop = ce->default_static_members_table[prop_info->offset];
|
|
|
|
} else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
|
|
|
|
prop = ce->default_properties_table[prop_info->offset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!prop) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-10-13 06:19:43 +08:00
|
|
|
|
2010-05-24 22:11:39 +08:00
|
|
|
/* copy: enforce read only access */
|
|
|
|
ALLOC_ZVAL(prop_copy);
|
|
|
|
*prop_copy = *prop;
|
|
|
|
zval_copy_ctor(prop_copy);
|
|
|
|
INIT_PZVAL(prop_copy);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2010-05-24 22:11:39 +08:00
|
|
|
/* this is necessary to make it able to work with default array
|
|
|
|
* properties, returned to user */
|
|
|
|
if (Z_TYPE_P(prop_copy) == IS_CONSTANT_ARRAY || (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
|
|
|
|
zval_update_constant(&prop_copy, 0 TSRMLS_CC);
|
2004-10-13 06:19:43 +08:00
|
|
|
}
|
2010-05-24 22:11:39 +08:00
|
|
|
|
|
|
|
add_assoc_zval(return_value, key, prop_copy);
|
2004-10-13 06:19:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2000-02-27 01:54:00 +08:00
|
|
|
/* {{{ proto array get_class_vars(string class_name)
|
2004-10-13 06:19:43 +08:00
|
|
|
Returns an array of default properties of the class. */
|
2000-02-27 01:54:00 +08:00
|
|
|
ZEND_FUNCTION(get_class_vars)
|
|
|
|
{
|
2004-10-13 06:19:43 +08:00
|
|
|
char *class_name;
|
|
|
|
int class_name_len;
|
|
|
|
zend_class_entry **pce;
|
2000-02-27 01:54:00 +08:00
|
|
|
|
2004-10-13 06:19:43 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) {
|
|
|
|
return;
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
|
2004-10-13 06:19:43 +08:00
|
|
|
if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC) == FAILURE) {
|
2000-02-27 01:54:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
array_init(return_value);
|
2005-09-01 18:05:32 +08:00
|
|
|
zend_update_class_constants(*pce TSRMLS_CC);
|
2010-05-24 22:11:39 +08:00
|
|
|
add_class_vars(*pce, 0, return_value TSRMLS_CC);
|
|
|
|
add_class_vars(*pce, 1, return_value TSRMLS_CC);
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2000-02-27 01:54:00 +08:00
|
|
|
/* {{{ proto array get_object_vars(object obj)
|
|
|
|
Returns an array of object properties */
|
|
|
|
ZEND_FUNCTION(get_object_vars)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *obj;
|
2003-11-11 05:03:04 +08:00
|
|
|
zval **value;
|
|
|
|
HashTable *properties;
|
|
|
|
HashPosition pos;
|
2011-09-13 21:29:35 +08:00
|
|
|
char *key;
|
|
|
|
const char *prop_name, *class_name;
|
2003-11-11 05:03:04 +08:00
|
|
|
uint key_len;
|
|
|
|
ulong num_index;
|
2007-07-24 19:39:56 +08:00
|
|
|
zend_object *zobj;
|
2000-02-27 01:54:00 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
|
|
|
|
return;
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
|
2002-02-07 22:08:43 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-02-27 01:54:00 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
properties = Z_OBJ_HT_P(obj)->get_properties(obj TSRMLS_CC);
|
2006-02-07 08:33:13 +08:00
|
|
|
|
|
|
|
if (properties == NULL) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
zobj = zend_objects_get_address(obj TSRMLS_CC);
|
2004-10-04 16:59:29 +08:00
|
|
|
|
2000-02-27 01:54:00 +08:00
|
|
|
array_init(return_value);
|
2003-11-11 05:03:04 +08:00
|
|
|
|
|
|
|
zend_hash_internal_pointer_reset_ex(properties, &pos);
|
|
|
|
|
|
|
|
while (zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS) {
|
2004-10-04 16:59:29 +08:00
|
|
|
if (zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos) == HASH_KEY_IS_STRING) {
|
2007-07-24 19:39:56 +08:00
|
|
|
if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) == SUCCESS) {
|
|
|
|
zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);
|
2004-10-04 16:59:29 +08:00
|
|
|
/* Not separating references */
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_PP(value);
|
2007-07-24 19:39:56 +08:00
|
|
|
add_assoc_zval_ex(return_value, prop_name, strlen(prop_name)+1, *value);
|
2004-10-04 16:59:29 +08:00
|
|
|
}
|
2003-11-11 05:03:04 +08:00
|
|
|
}
|
|
|
|
zend_hash_move_forward_ex(properties, &pos);
|
|
|
|
}
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2001-03-27 04:14:21 +08:00
|
|
|
/* {{{ proto array get_class_methods(mixed class)
|
|
|
|
Returns an array of method names for class or class instance. */
|
2000-03-24 01:47:28 +08:00
|
|
|
ZEND_FUNCTION(get_class_methods)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *klass;
|
2000-03-24 01:47:28 +08:00
|
|
|
zval *method_name;
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_class_entry *ce = NULL, **pce;
|
2003-09-19 00:20:42 +08:00
|
|
|
HashPosition pos;
|
|
|
|
zend_function *mptr;
|
2000-03-24 01:47:28 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &klass) == FAILURE) {
|
|
|
|
return;
|
2000-03-24 01:47:28 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(klass) == IS_OBJECT) {
|
2002-02-07 22:08:43 +08:00
|
|
|
/* TBI!! new object handlers */
|
2008-06-19 07:38:37 +08:00
|
|
|
if (!HAS_CLASS_ENTRY(*klass)) {
|
2002-02-07 22:08:43 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
ce = Z_OBJCE_P(klass);
|
|
|
|
} else if (Z_TYPE_P(klass) == IS_STRING) {
|
|
|
|
if (zend_lookup_class(Z_STRVAL_P(klass), Z_STRLEN_P(klass), &pce TSRMLS_CC) == SUCCESS) {
|
2002-03-12 18:08:47 +08:00
|
|
|
ce = *pce;
|
|
|
|
}
|
2001-03-27 04:14:21 +08:00
|
|
|
}
|
2000-03-24 01:47:28 +08:00
|
|
|
|
2001-03-27 04:14:21 +08:00
|
|
|
if (!ce) {
|
2000-03-24 02:31:18 +08:00
|
|
|
RETURN_NULL();
|
2001-03-27 04:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2003-09-19 00:20:42 +08:00
|
|
|
zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
|
|
|
|
|
|
|
|
while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) {
|
2004-10-12 19:01:08 +08:00
|
|
|
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
|
2005-05-03 16:52:04 +08:00
|
|
|
|| (EG(scope) &&
|
|
|
|
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
|
2008-02-21 23:14:27 +08:00
|
|
|
zend_check_protected(mptr->common.scope, EG(scope)))
|
2005-05-03 16:52:04 +08:00
|
|
|
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
|
|
|
|
EG(scope) == mptr->common.scope)))) {
|
2006-09-26 15:55:21 +08:00
|
|
|
char *key;
|
|
|
|
uint key_len;
|
|
|
|
ulong num_index;
|
|
|
|
uint len = strlen(mptr->common.function_name);
|
|
|
|
|
|
|
|
/* Do not display old-style inherited constructors */
|
|
|
|
if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
|
|
|
|
mptr->common.scope == ce ||
|
|
|
|
zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING ||
|
|
|
|
zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) {
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(method_name);
|
|
|
|
ZVAL_STRINGL(method_name, mptr->common.function_name, len, 1);
|
|
|
|
zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
|
|
|
|
}
|
2004-10-12 19:01:08 +08:00
|
|
|
}
|
2003-09-19 00:20:42 +08:00
|
|
|
zend_hash_move_forward_ex(&ce->function_table, &pos);
|
2000-03-24 01:47:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2003-11-28 01:06:26 +08:00
|
|
|
|
|
|
|
|
1999-09-21 05:28:37 +08:00
|
|
|
/* {{{ proto bool method_exists(object object, string method)
|
2000-02-28 02:41:19 +08:00
|
|
|
Checks if the class method exists */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(method_exists)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *klass;
|
|
|
|
char *method_name;
|
|
|
|
int method_len;
|
1999-12-15 05:15:24 +08:00
|
|
|
char *lcname;
|
2005-02-27 23:03:09 +08:00
|
|
|
zend_class_entry * ce, **pce;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &klass, &method_name, &method_len) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(klass) == IS_OBJECT) {
|
|
|
|
ce = Z_OBJCE_P(klass);
|
|
|
|
} else if (Z_TYPE_P(klass) == IS_STRING) {
|
|
|
|
if (zend_lookup_class(Z_STRVAL_P(klass), Z_STRLEN_P(klass), &pce TSRMLS_CC) == FAILURE) {
|
2005-02-27 23:03:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2005-04-16 23:24:56 +08:00
|
|
|
ce = *pce;
|
2005-02-27 23:03:09 +08:00
|
|
|
} else {
|
2002-02-07 22:08:43 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
lcname = zend_str_tolower_dup(method_name, method_len);
|
|
|
|
if (zend_hash_exists(&ce->function_table, lcname, method_len+1)) {
|
1999-12-15 05:15:24 +08:00
|
|
|
efree(lcname);
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
2005-04-26 16:47:31 +08:00
|
|
|
union _zend_function *func = NULL;
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(klass) == IS_OBJECT
|
|
|
|
&& Z_OBJ_HT_P(klass)->get_method != NULL
|
2010-04-20 18:57:45 +08:00
|
|
|
&& (func = Z_OBJ_HT_P(klass)->get_method(&klass, method_name, method_len, NULL TSRMLS_CC)) != NULL
|
2005-03-01 02:53:33 +08:00
|
|
|
) {
|
2005-04-26 16:47:31 +08:00
|
|
|
if (func->type == ZEND_INTERNAL_FUNCTION
|
2010-06-12 07:20:13 +08:00
|
|
|
&& (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0
|
2005-04-26 16:47:31 +08:00
|
|
|
) {
|
2010-06-12 07:20:13 +08:00
|
|
|
/* Returns true to the fake Closure's __invoke */
|
|
|
|
RETVAL_BOOL((func->common.scope == zend_ce_closure
|
|
|
|
&& (method_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
|
|
|
|
&& memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) ? 1 : 0);
|
|
|
|
|
|
|
|
efree(lcname);
|
2011-09-13 21:29:35 +08:00
|
|
|
efree((char*)((zend_internal_function*)func)->function_name);
|
2005-04-26 16:47:31 +08:00
|
|
|
efree(func);
|
2010-06-12 07:20:13 +08:00
|
|
|
return;
|
2005-04-26 16:47:31 +08:00
|
|
|
}
|
2010-06-12 07:20:13 +08:00
|
|
|
efree(lcname);
|
2005-03-01 02:53:33 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
2010-06-12 07:20:13 +08:00
|
|
|
efree(lcname);
|
2005-03-01 02:53:33 +08:00
|
|
|
RETURN_FALSE;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-04-08 21:33:15 +08:00
|
|
|
/* {{{ proto bool property_exists(mixed object_or_class, string property_name)
|
|
|
|
Checks if the object or class has a property */
|
|
|
|
ZEND_FUNCTION(property_exists)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *object;
|
|
|
|
char *property;
|
|
|
|
int property_len;
|
2005-04-08 21:33:15 +08:00
|
|
|
zend_class_entry *ce, **pce;
|
|
|
|
zend_property_info *property_info;
|
2008-06-19 07:38:37 +08:00
|
|
|
zval property_z;
|
2008-08-19 01:44:02 +08:00
|
|
|
ulong h;
|
2005-04-08 21:33:15 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &object, &property, &property_len) == FAILURE) {
|
|
|
|
return;
|
2005-04-08 21:33:15 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
|
|
|
if (property_len == 0) {
|
2005-04-16 02:53:42 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2005-04-08 21:33:15 +08:00
|
|
|
|
2008-08-19 01:44:02 +08:00
|
|
|
if (Z_TYPE_P(object) == IS_STRING) {
|
|
|
|
if (zend_lookup_class(Z_STRVAL_P(object), Z_STRLEN_P(object), &pce TSRMLS_CC) == FAILURE) {
|
2005-04-08 21:33:15 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2008-08-19 01:44:02 +08:00
|
|
|
ce = *pce;
|
|
|
|
} else if (Z_TYPE_P(object) == IS_OBJECT) {
|
|
|
|
ce = Z_OBJCE_P(object);
|
|
|
|
} else {
|
|
|
|
zend_error(E_WARNING, "First parameter must either be an object or the name of an existing class");
|
|
|
|
RETURN_NULL();
|
|
|
|
}
|
|
|
|
|
|
|
|
h = zend_get_hash_value(property, property_len+1);
|
2010-03-07 08:49:34 +08:00
|
|
|
if (zend_hash_quick_find(&ce->properties_info, property, property_len+1, h, (void **) &property_info) == SUCCESS
|
|
|
|
&& (property_info->flags & ZEND_ACC_SHADOW) == 0) {
|
2008-08-19 01:44:02 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-08-19 01:44:02 +08:00
|
|
|
ZVAL_STRINGL(&property_z, property, property_len, 0);
|
2005-04-08 21:33:15 +08:00
|
|
|
|
2008-08-19 01:44:02 +08:00
|
|
|
if (Z_TYPE_P(object) == IS_OBJECT &&
|
|
|
|
Z_OBJ_HANDLER_P(object, has_property) &&
|
2010-04-20 18:57:45 +08:00
|
|
|
Z_OBJ_HANDLER_P(object, has_property)(object, &property_z, 2, 0 TSRMLS_CC)) {
|
2008-08-19 01:44:02 +08:00
|
|
|
RETURN_TRUE;
|
2005-04-08 21:33:15 +08:00
|
|
|
}
|
2008-08-19 01:44:02 +08:00
|
|
|
RETURN_FALSE;
|
2005-04-08 21:33:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2004-04-28 02:09:40 +08:00
|
|
|
/* {{{ proto bool class_exists(string classname [, bool autoload])
|
2000-02-28 02:41:19 +08:00
|
|
|
Checks if the class exists */
|
1999-12-15 05:15:24 +08:00
|
|
|
ZEND_FUNCTION(class_exists)
|
|
|
|
{
|
2004-04-28 02:09:40 +08:00
|
|
|
char *class_name, *lc_name;
|
2003-04-09 02:22:32 +08:00
|
|
|
zend_class_entry **ce;
|
2004-06-18 02:23:47 +08:00
|
|
|
int class_name_len;
|
2004-04-28 02:09:40 +08:00
|
|
|
int found;
|
2007-11-22 21:27:13 +08:00
|
|
|
zend_bool autoload = 1;
|
|
|
|
ALLOCA_FLAG(use_heap)
|
1999-12-15 05:15:24 +08:00
|
|
|
|
2004-04-28 02:09:40 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &class_name, &class_name_len, &autoload) == FAILURE) {
|
|
|
|
return;
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
2003-04-09 02:22:32 +08:00
|
|
|
|
2004-04-28 02:09:40 +08:00
|
|
|
if (!autoload) {
|
2008-12-10 03:17:11 +08:00
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
|
2007-11-22 21:27:13 +08:00
|
|
|
lc_name = do_alloca(class_name_len + 1, use_heap);
|
2004-04-28 02:09:40 +08:00
|
|
|
zend_str_tolower_copy(lc_name, class_name, class_name_len);
|
2008-12-10 03:17:11 +08:00
|
|
|
|
|
|
|
/* Ignore leading "\" */
|
|
|
|
name = lc_name;
|
|
|
|
len = class_name_len;
|
|
|
|
if (lc_name[0] == '\\') {
|
|
|
|
name = &lc_name[1];
|
|
|
|
len--;
|
|
|
|
}
|
2004-04-28 02:09:40 +08:00
|
|
|
|
2008-12-10 03:17:11 +08:00
|
|
|
found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce);
|
2007-11-22 21:27:13 +08:00
|
|
|
free_alloca(lc_name, use_heap);
|
2011-07-25 19:51:43 +08:00
|
|
|
RETURN_BOOL(found == SUCCESS && !(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
|
2004-04-28 02:09:40 +08:00
|
|
|
}
|
2003-11-25 02:13:29 +08:00
|
|
|
|
2004-04-28 02:09:40 +08:00
|
|
|
if (zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC) == SUCCESS) {
|
2011-01-10 03:57:41 +08:00
|
|
|
RETURN_BOOL(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0);
|
2004-08-25 08:41:43 +08:00
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool interface_exists(string classname [, bool autoload])
|
|
|
|
Checks if the class exists */
|
|
|
|
ZEND_FUNCTION(interface_exists)
|
|
|
|
{
|
|
|
|
char *iface_name, *lc_name;
|
|
|
|
zend_class_entry **ce;
|
|
|
|
int iface_name_len;
|
|
|
|
int found;
|
2007-11-22 21:27:13 +08:00
|
|
|
zend_bool autoload = 1;
|
|
|
|
ALLOCA_FLAG(use_heap)
|
2004-08-25 08:41:43 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &iface_name, &iface_name_len, &autoload) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!autoload) {
|
2009-03-09 01:28:39 +08:00
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
|
2007-11-22 21:27:13 +08:00
|
|
|
lc_name = do_alloca(iface_name_len + 1, use_heap);
|
2004-08-25 08:41:43 +08:00
|
|
|
zend_str_tolower_copy(lc_name, iface_name, iface_name_len);
|
|
|
|
|
2009-03-09 01:28:39 +08:00
|
|
|
/* Ignore leading "\" */
|
|
|
|
name = lc_name;
|
|
|
|
len = iface_name_len;
|
|
|
|
if (lc_name[0] == '\\') {
|
|
|
|
name = &lc_name[1];
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce);
|
2007-11-22 21:27:13 +08:00
|
|
|
free_alloca(lc_name, use_heap);
|
2004-08-25 08:41:43 +08:00
|
|
|
RETURN_BOOL(found == SUCCESS && (*ce)->ce_flags & ZEND_ACC_INTERFACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_lookup_class(iface_name, iface_name_len, &ce TSRMLS_CC) == SUCCESS) {
|
|
|
|
RETURN_BOOL(((*ce)->ce_flags & ZEND_ACC_INTERFACE) > 0);
|
1999-12-15 05:15:24 +08:00
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2011-01-10 03:57:41 +08:00
|
|
|
/* {{{ proto bool trait_exists(string traitname [, bool autoload])
|
|
|
|
Checks if the trait exists */
|
|
|
|
ZEND_FUNCTION(trait_exists)
|
|
|
|
{
|
|
|
|
char *trait_name, *lc_name;
|
|
|
|
zend_class_entry **ce;
|
|
|
|
int trait_name_len;
|
|
|
|
int found;
|
|
|
|
zend_bool autoload = 1;
|
|
|
|
ALLOCA_FLAG(use_heap)
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &trait_name, &trait_name_len, &autoload) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!autoload) {
|
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
lc_name = do_alloca(trait_name_len + 1, use_heap);
|
|
|
|
zend_str_tolower_copy(lc_name, trait_name, trait_name_len);
|
|
|
|
|
|
|
|
/* Ignore leading "\" */
|
|
|
|
name = lc_name;
|
|
|
|
len = trait_name_len;
|
|
|
|
if (lc_name[0] == '\\') {
|
|
|
|
name = &lc_name[1];
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce);
|
|
|
|
free_alloca(lc_name, use_heap);
|
|
|
|
RETURN_BOOL(found == SUCCESS && (((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_lookup_class(trait_name, trait_name_len, &ce TSRMLS_CC) == SUCCESS) {
|
|
|
|
RETURN_BOOL(((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
1999-12-15 05:15:24 +08:00
|
|
|
/* {{{ proto bool function_exists(string function_name)
|
|
|
|
Checks if the function exists */
|
|
|
|
ZEND_FUNCTION(function_exists)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *name;
|
|
|
|
int name_len;
|
2002-09-16 09:36:48 +08:00
|
|
|
zend_function *func;
|
2003-08-18 03:14:30 +08:00
|
|
|
char *lcname;
|
2002-09-16 09:36:48 +08:00
|
|
|
zend_bool retval;
|
1999-12-15 05:15:24 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
|
|
|
|
return;
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
1999-12-23 02:49:23 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
lcname = zend_str_tolower_dup(name, name_len);
|
2009-03-09 01:28:39 +08:00
|
|
|
|
|
|
|
/* Ignore leading "\" */
|
|
|
|
name = lcname;
|
|
|
|
if (lcname[0] == '\\') {
|
|
|
|
name = &lcname[1];
|
|
|
|
name_len--;
|
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
2009-03-09 01:28:39 +08:00
|
|
|
retval = (zend_hash_find(EG(function_table), name, name_len+1, (void **)&func) == SUCCESS);
|
2003-06-02 20:13:11 +08:00
|
|
|
|
1999-12-23 02:49:23 +08:00
|
|
|
efree(lcname);
|
|
|
|
|
2002-09-16 09:36:48 +08:00
|
|
|
/*
|
|
|
|
* A bit of a hack, but not a bad one: we see if the handler of the function
|
|
|
|
* is actually one that displays "function is disabled" message.
|
|
|
|
*/
|
2003-04-22 01:01:34 +08:00
|
|
|
if (retval && func->type == ZEND_INTERNAL_FUNCTION &&
|
2002-09-16 09:36:48 +08:00
|
|
|
func->internal_function.handler == zif_display_disabled_function) {
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
|
1999-12-23 02:49:23 +08:00
|
|
|
RETURN_BOOL(retval);
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2008-05-12 15:11:55 +08:00
|
|
|
/* {{{ proto bool class_alias(string user_class_name , string alias_name [, bool autoload])
|
|
|
|
Creates an alias for user defined class */
|
|
|
|
ZEND_FUNCTION(class_alias)
|
|
|
|
{
|
|
|
|
char *class_name, *lc_name, *alias_name;
|
|
|
|
zend_class_entry **ce;
|
|
|
|
int class_name_len, alias_name_len;
|
|
|
|
int found;
|
|
|
|
zend_bool autoload = 1;
|
|
|
|
ALLOCA_FLAG(use_heap)
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &class_name, &class_name_len, &alias_name, &alias_name_len, &autoload) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!autoload) {
|
|
|
|
lc_name = do_alloca(class_name_len + 1, use_heap);
|
|
|
|
zend_str_tolower_copy(lc_name, class_name, class_name_len);
|
|
|
|
|
|
|
|
found = zend_hash_find(EG(class_table), lc_name, class_name_len+1, (void **) &ce);
|
|
|
|
free_alloca(lc_name, use_heap);
|
|
|
|
} else {
|
|
|
|
found = zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (found == SUCCESS) {
|
|
|
|
if ((*ce)->type == ZEND_USER_CLASS) {
|
|
|
|
if (zend_register_class_alias_ex(alias_name, alias_name_len, *ce TSRMLS_CC) == SUCCESS) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
zend_error(E_WARNING, "Cannot redeclare class %s", alias_name);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zend_error(E_WARNING, "First argument of class_alias() must be a name of user defined class");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zend_error(E_WARNING, "Class '%s' not found", class_name);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-11-21 03:44:37 +08:00
|
|
|
#if ZEND_DEBUG
|
2001-12-05 01:58:32 +08:00
|
|
|
/* {{{ proto void leak(int num_bytes=3)
|
|
|
|
Cause an intentional memory leak, for testing/debugging purposes */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(leak)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
long leakbytes=3;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &leakbytes) == FAILURE) {
|
|
|
|
return;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
1999-09-21 05:28:37 +08:00
|
|
|
emalloc(leakbytes);
|
|
|
|
}
|
2001-12-05 01:58:32 +08:00
|
|
|
/* }}} */
|
1999-12-04 22:26:26 +08:00
|
|
|
|
2010-11-16 01:06:27 +08:00
|
|
|
/* {{{ proto leak_variable(mixed variable [, bool leak_data]) */
|
|
|
|
ZEND_FUNCTION(leak_variable)
|
|
|
|
{
|
|
|
|
zval *zv;
|
|
|
|
zend_bool leak_data = 0;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zv, &leak_data) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!leak_data) {
|
|
|
|
zval_add_ref(&zv);
|
|
|
|
} else if (Z_TYPE_P(zv) == IS_RESOURCE) {
|
|
|
|
zend_list_addref(Z_RESVAL_P(zv));
|
|
|
|
} else if (Z_TYPE_P(zv) == IS_OBJECT) {
|
|
|
|
Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC);
|
|
|
|
} else {
|
|
|
|
zend_error(E_WARNING, "Leaking non-zval data is only applicable to resources and objects");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-12-04 22:26:26 +08:00
|
|
|
|
2000-02-15 03:08:51 +08:00
|
|
|
#ifdef ZEND_TEST_EXCEPTIONS
|
2000-02-13 09:22:11 +08:00
|
|
|
ZEND_FUNCTION(crash)
|
|
|
|
{
|
|
|
|
char *nowhere=NULL;
|
|
|
|
|
|
|
|
memcpy(nowhere, "something", sizeof("something"));
|
|
|
|
}
|
2000-02-15 03:08:51 +08:00
|
|
|
#endif
|
2000-02-13 09:22:11 +08:00
|
|
|
|
2002-11-21 03:44:37 +08:00
|
|
|
#endif /* ZEND_DEBUG */
|
2000-02-13 09:22:11 +08:00
|
|
|
|
2000-04-19 21:15:13 +08:00
|
|
|
/* {{{ proto array get_included_files(void)
|
|
|
|
Returns an array with the file names that were include_once()'d */
|
2000-03-11 00:36:30 +08:00
|
|
|
ZEND_FUNCTION(get_included_files)
|
1999-12-04 22:26:26 +08:00
|
|
|
{
|
2000-09-18 21:43:20 +08:00
|
|
|
char *entry;
|
2011-09-13 21:29:35 +08:00
|
|
|
|
2008-03-11 06:02:41 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
2000-05-02 00:22:00 +08:00
|
|
|
}
|
|
|
|
|
1999-12-04 22:26:26 +08:00
|
|
|
array_init(return_value);
|
2000-09-18 21:43:20 +08:00
|
|
|
zend_hash_internal_pointer_reset(&EG(included_files));
|
2001-04-28 02:53:25 +08:00
|
|
|
while (zend_hash_get_current_key(&EG(included_files), &entry, NULL, 1) == HASH_KEY_IS_STRING) {
|
2001-04-30 21:04:27 +08:00
|
|
|
add_next_index_string(return_value, entry, 0);
|
2000-09-18 21:43:20 +08:00
|
|
|
zend_hash_move_forward(&EG(included_files));
|
|
|
|
}
|
2001-04-30 21:05:11 +08:00
|
|
|
}
|
2000-04-19 21:15:13 +08:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2010-05-02 02:54:49 +08:00
|
|
|
/* {{{ proto void trigger_error(string message [, int error_type])
|
2000-04-19 21:15:13 +08:00
|
|
|
Generates a user-level error/warning/notice message */
|
2000-06-02 20:36:54 +08:00
|
|
|
ZEND_FUNCTION(trigger_error)
|
2000-04-19 21:15:13 +08:00
|
|
|
{
|
2008-07-01 15:23:00 +08:00
|
|
|
long error_type = E_USER_NOTICE;
|
2008-06-19 07:38:37 +08:00
|
|
|
char *message;
|
|
|
|
int message_len;
|
2000-04-19 21:15:13 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &message, &message_len, &error_type) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (error_type) {
|
|
|
|
case E_USER_ERROR:
|
|
|
|
case E_USER_WARNING:
|
|
|
|
case E_USER_NOTICE:
|
2008-07-21 17:41:00 +08:00
|
|
|
case E_USER_DEPRECATED:
|
2000-04-19 21:15:13 +08:00
|
|
|
break;
|
2000-09-05 20:08:41 +08:00
|
|
|
default:
|
2008-06-19 07:38:37 +08:00
|
|
|
zend_error(E_WARNING, "Invalid error type specified");
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
2000-04-19 21:15:13 +08:00
|
|
|
}
|
2008-06-19 07:38:37 +08:00
|
|
|
|
2008-07-01 15:23:00 +08:00
|
|
|
zend_error((int)error_type, "%s", message);
|
2000-04-19 21:15:13 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2000-04-19 23:08:06 +08:00
|
|
|
|
|
|
|
|
2004-01-10 19:43:42 +08:00
|
|
|
/* {{{ proto string set_error_handler(string error_handler [, int error_types])
|
2000-06-13 06:03:53 +08:00
|
|
|
Sets a user-defined error handler function. Returns the previously defined error handler, or false on error */
|
2000-06-02 20:36:54 +08:00
|
|
|
ZEND_FUNCTION(set_error_handler)
|
2000-04-19 23:08:06 +08:00
|
|
|
{
|
2004-01-10 19:43:42 +08:00
|
|
|
zval *error_handler;
|
2000-06-13 04:31:02 +08:00
|
|
|
zend_bool had_orig_error_handler=0;
|
2003-04-20 22:20:20 +08:00
|
|
|
char *error_handler_name = NULL;
|
2011-07-24 06:07:22 +08:00
|
|
|
long error_type = E_ALL;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2004-01-10 19:43:42 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &error_handler, &error_type) == FAILURE) {
|
|
|
|
return;
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
|
|
|
|
2008-08-02 12:46:07 +08:00
|
|
|
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
|
2003-04-20 22:18:15 +08:00
|
|
|
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
|
2003-04-20 22:20:20 +08:00
|
|
|
get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown");
|
2003-04-20 22:18:15 +08:00
|
|
|
efree(error_handler_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
efree(error_handler_name);
|
|
|
|
|
2000-04-19 23:08:06 +08:00
|
|
|
if (EG(user_error_handler)) {
|
2000-06-13 04:31:02 +08:00
|
|
|
had_orig_error_handler = 1;
|
|
|
|
*return_value = *EG(user_error_handler);
|
2000-06-18 02:04:58 +08:00
|
|
|
zval_copy_ctor(return_value);
|
2008-02-20 00:39:18 +08:00
|
|
|
INIT_PZVAL(return_value);
|
2004-01-10 19:43:42 +08:00
|
|
|
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting)));
|
2000-06-18 02:04:58 +08:00
|
|
|
zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler));
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
2000-06-18 02:04:58 +08:00
|
|
|
ALLOC_ZVAL(EG(user_error_handler));
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2004-01-10 19:43:42 +08:00
|
|
|
if (!zend_is_true(error_handler)) { /* unset user-defined handler */
|
2003-06-08 22:00:11 +08:00
|
|
|
FREE_ZVAL(EG(user_error_handler));
|
|
|
|
EG(user_error_handler) = NULL;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2000-06-02 20:36:54 +08:00
|
|
|
|
2004-01-10 19:43:42 +08:00
|
|
|
EG(user_error_handler_error_reporting) = (int)error_type;
|
|
|
|
*EG(user_error_handler) = *error_handler;
|
2000-04-19 23:08:06 +08:00
|
|
|
zval_copy_ctor(EG(user_error_handler));
|
2008-02-20 00:39:18 +08:00
|
|
|
INIT_PZVAL(EG(user_error_handler));
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-06-13 04:31:02 +08:00
|
|
|
if (!had_orig_error_handler) {
|
2000-06-18 02:04:58 +08:00
|
|
|
RETURN_NULL();
|
2000-06-13 04:31:02 +08:00
|
|
|
}
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
2000-06-02 20:36:54 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2000-05-02 00:22:00 +08:00
|
|
|
|
2000-06-18 02:04:58 +08:00
|
|
|
/* {{{ proto void restore_error_handler(void)
|
|
|
|
Restores the previously defined error handler function */
|
|
|
|
ZEND_FUNCTION(restore_error_handler)
|
|
|
|
{
|
|
|
|
if (EG(user_error_handler)) {
|
2004-05-24 04:27:32 +08:00
|
|
|
zval *zeh = EG(user_error_handler);
|
|
|
|
|
|
|
|
EG(user_error_handler) = NULL;
|
|
|
|
zval_ptr_dtor(&zeh);
|
2000-06-18 02:04:58 +08:00
|
|
|
}
|
2004-05-24 04:27:32 +08:00
|
|
|
|
2000-06-18 02:04:58 +08:00
|
|
|
if (zend_ptr_stack_num_elements(&EG(user_error_handlers))==0) {
|
|
|
|
EG(user_error_handler) = NULL;
|
|
|
|
} else {
|
2004-01-10 19:43:42 +08:00
|
|
|
EG(user_error_handler_error_reporting) = zend_stack_int_top(&EG(user_error_handlers_error_reporting));
|
|
|
|
zend_stack_del_top(&EG(user_error_handlers_error_reporting));
|
2000-06-18 02:04:58 +08:00
|
|
|
EG(user_error_handler) = zend_ptr_stack_pop(&EG(user_error_handlers));
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2002-07-05 10:34:54 +08:00
|
|
|
/* }}} */
|
2000-06-18 02:04:58 +08:00
|
|
|
|
|
|
|
|
2004-04-04 05:50:12 +08:00
|
|
|
/* {{{ proto string set_exception_handler(callable exception_handler)
|
2002-08-16 08:41:37 +08:00
|
|
|
Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
|
|
|
|
ZEND_FUNCTION(set_exception_handler)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *exception_handler;
|
2004-04-04 05:50:12 +08:00
|
|
|
char *exception_handler_name = NULL;
|
2002-08-16 08:41:37 +08:00
|
|
|
zend_bool had_orig_exception_handler=0;
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &exception_handler) == FAILURE) {
|
|
|
|
return;
|
2002-08-16 08:41:37 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
|
2008-08-02 12:46:07 +08:00
|
|
|
if (!zend_is_callable(exception_handler, 0, &exception_handler_name TSRMLS_CC)) {
|
2004-10-12 17:13:20 +08:00
|
|
|
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
|
|
|
|
get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
|
|
|
|
efree(exception_handler_name);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-04 05:50:12 +08:00
|
|
|
efree(exception_handler_name);
|
|
|
|
}
|
|
|
|
|
2002-08-16 08:41:37 +08:00
|
|
|
if (EG(user_exception_handler)) {
|
|
|
|
had_orig_exception_handler = 1;
|
|
|
|
*return_value = *EG(user_exception_handler);
|
|
|
|
zval_copy_ctor(return_value);
|
|
|
|
zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
|
|
|
|
}
|
|
|
|
ALLOC_ZVAL(EG(user_exception_handler));
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
|
2002-08-16 08:41:37 +08:00
|
|
|
FREE_ZVAL(EG(user_exception_handler));
|
|
|
|
EG(user_exception_handler) = NULL;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
*EG(user_exception_handler) = *exception_handler;
|
2002-08-16 08:41:37 +08:00
|
|
|
zval_copy_ctor(EG(user_exception_handler));
|
|
|
|
|
|
|
|
if (!had_orig_exception_handler) {
|
|
|
|
RETURN_NULL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto void restore_exception_handler(void)
|
|
|
|
Restores the previously defined exception handler function */
|
|
|
|
ZEND_FUNCTION(restore_exception_handler)
|
|
|
|
{
|
|
|
|
if (EG(user_exception_handler)) {
|
|
|
|
zval_ptr_dtor(&EG(user_exception_handler));
|
|
|
|
}
|
|
|
|
if (zend_ptr_stack_num_elements(&EG(user_exception_handlers))==0) {
|
|
|
|
EG(user_exception_handler) = NULL;
|
|
|
|
} else {
|
|
|
|
EG(user_exception_handler) = zend_ptr_stack_pop(&EG(user_exception_handlers));
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2008-07-25 03:52:24 +08:00
|
|
|
static int copy_class_or_interface_name(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
2000-05-02 00:22:00 +08:00
|
|
|
{
|
2000-06-09 23:40:37 +08:00
|
|
|
zval *array = va_arg(args, zval *);
|
2004-09-27 16:43:05 +08:00
|
|
|
zend_uint mask = va_arg(args, zend_uint);
|
|
|
|
zend_uint comply = va_arg(args, zend_uint);
|
|
|
|
zend_uint comply_mask = (comply)? mask:0;
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_class_entry *ce = *pce;
|
2000-06-09 23:40:37 +08:00
|
|
|
|
2003-12-08 02:54:31 +08:00
|
|
|
if ((hash_key->nKeyLength==0 || hash_key->arKey[0]!=0)
|
|
|
|
&& (comply_mask == (ce->ce_flags & mask))) {
|
2003-06-02 20:13:11 +08:00
|
|
|
add_next_index_stringl(array, ce->name, ce->name_length, 1);
|
2000-06-09 23:40:37 +08:00
|
|
|
}
|
2003-12-08 02:54:31 +08:00
|
|
|
return ZEND_HASH_APPLY_KEEP;
|
2000-05-02 00:22:00 +08:00
|
|
|
}
|
|
|
|
|
2010-05-06 23:18:20 +08:00
|
|
|
/* {{{ proto array get_declared_traits()
|
|
|
|
Returns an array of all declared traits. */
|
|
|
|
ZEND_FUNCTION(get_declared_traits)
|
|
|
|
{
|
|
|
|
zend_uint mask = ZEND_ACC_TRAIT;
|
|
|
|
zend_uint comply = 1;
|
|
|
|
|
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2003-06-02 20:13:11 +08:00
|
|
|
/* {{{ proto array get_declared_classes()
|
2000-05-02 00:22:00 +08:00
|
|
|
Returns an array of all declared classes. */
|
|
|
|
ZEND_FUNCTION(get_declared_classes)
|
|
|
|
{
|
2010-05-06 23:18:20 +08:00
|
|
|
zend_uint mask = ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
|
2004-09-27 16:43:05 +08:00
|
|
|
zend_uint comply = 0;
|
2003-12-08 02:54:31 +08:00
|
|
|
|
2008-03-11 06:02:41 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
2003-06-09 08:15:11 +08:00
|
|
|
}
|
2003-12-08 02:54:31 +08:00
|
|
|
|
|
|
|
array_init(return_value);
|
2008-07-25 03:52:24 +08:00
|
|
|
zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply);
|
2003-12-08 02:54:31 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto array get_declared_interfaces()
|
|
|
|
Returns an array of all declared interfaces. */
|
|
|
|
ZEND_FUNCTION(get_declared_interfaces)
|
|
|
|
{
|
2004-09-27 16:43:05 +08:00
|
|
|
zend_uint mask = ZEND_ACC_INTERFACE;
|
|
|
|
zend_uint comply = 1;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-03-11 06:02:41 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
2003-12-08 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
2000-05-02 00:22:00 +08:00
|
|
|
array_init(return_value);
|
2008-07-25 03:52:24 +08:00
|
|
|
zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply);
|
2000-05-02 00:22:00 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-06-03 09:49:49 +08:00
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2008-07-25 03:52:24 +08:00
|
|
|
static int copy_function_name(zend_function *func TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
2000-10-14 23:52:24 +08:00
|
|
|
{
|
2000-10-15 03:48:53 +08:00
|
|
|
zval *internal_ar = va_arg(args, zval *),
|
|
|
|
*user_ar = va_arg(args, zval *);
|
|
|
|
|
|
|
|
if (hash_key->nKeyLength == 0 || hash_key->arKey[0] == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (func->type == ZEND_INTERNAL_FUNCTION) {
|
2001-03-23 22:46:37 +08:00
|
|
|
add_next_index_stringl(internal_ar, hash_key->arKey, hash_key->nKeyLength-1, 1);
|
2000-10-15 03:48:53 +08:00
|
|
|
} else if (func->type == ZEND_USER_FUNCTION) {
|
2001-03-23 22:46:37 +08:00
|
|
|
add_next_index_stringl(user_ar, hash_key->arKey, hash_key->nKeyLength-1, 1);
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2000-10-14 23:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2000-10-14 23:52:24 +08:00
|
|
|
/* {{{ proto array get_defined_functions(void)
|
|
|
|
Returns an array of all defined functions */
|
|
|
|
ZEND_FUNCTION(get_defined_functions)
|
|
|
|
{
|
2000-10-15 03:48:53 +08:00
|
|
|
zval *internal;
|
|
|
|
zval *user;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-03-11 06:02:41 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2000-10-15 03:48:53 +08:00
|
|
|
MAKE_STD_ZVAL(internal);
|
|
|
|
MAKE_STD_ZVAL(user);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2000-10-15 03:48:53 +08:00
|
|
|
array_init(internal);
|
|
|
|
array_init(user);
|
2000-10-14 23:52:24 +08:00
|
|
|
array_init(return_value);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2008-07-25 03:52:24 +08:00
|
|
|
zend_hash_apply_with_arguments(EG(function_table) TSRMLS_CC, (apply_func_args_t) copy_function_name, 2, internal, user);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
|
|
|
if (zend_hash_add(Z_ARRVAL_P(return_value), "internal", sizeof("internal"), (void **)&internal, sizeof(zval *), NULL) == FAILURE) {
|
2006-12-21 07:19:56 +08:00
|
|
|
zval_ptr_dtor(&internal);
|
|
|
|
zval_ptr_dtor(&user);
|
|
|
|
zval_dtor(return_value);
|
2000-10-15 03:48:53 +08:00
|
|
|
zend_error(E_WARNING, "Cannot add internal functions to return value from get_defined_functions()");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
|
|
|
if (zend_hash_add(Z_ARRVAL_P(return_value), "user", sizeof("user"), (void **)&user, sizeof(zval *), NULL) == FAILURE) {
|
2006-12-21 07:19:56 +08:00
|
|
|
zval_ptr_dtor(&user);
|
|
|
|
zval_dtor(return_value);
|
2000-10-15 03:48:53 +08:00
|
|
|
zend_error(E_WARNING, "Cannot add user functions to return value from get_defined_functions()");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2000-10-14 23:52:24 +08:00
|
|
|
/* {{{ proto array get_defined_vars(void)
|
2000-11-21 23:29:02 +08:00
|
|
|
Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
|
2000-10-14 23:52:24 +08:00
|
|
|
ZEND_FUNCTION(get_defined_vars)
|
2006-05-10 07:53:23 +08:00
|
|
|
{
|
2008-04-29 16:15:20 +08:00
|
|
|
if (!EG(active_symbol_table)) {
|
|
|
|
zend_rebuild_symbol_table(TSRMLS_C);
|
|
|
|
}
|
|
|
|
|
2008-05-27 18:29:33 +08:00
|
|
|
array_init_size(return_value, zend_hash_num_elements(EG(active_symbol_table)));
|
|
|
|
|
2006-05-10 07:53:23 +08:00
|
|
|
zend_hash_copy(Z_ARRVAL_P(return_value), EG(active_symbol_table),
|
2008-05-27 18:29:33 +08:00
|
|
|
(copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval *));
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-06-03 09:49:49 +08:00
|
|
|
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
#define LAMBDA_TEMP_FUNCNAME "__lambda_func"
|
2000-06-05 14:52:02 +08:00
|
|
|
/* {{{ proto string create_function(string args, string code)
|
2000-06-03 09:49:49 +08:00
|
|
|
Creates an anonymous function, and returns its name (funny, eh?) */
|
2000-06-05 05:30:56 +08:00
|
|
|
ZEND_FUNCTION(create_function)
|
2000-06-03 09:49:49 +08:00
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *eval_code, *function_name, *function_args, *function_code;
|
2009-06-06 02:50:32 +08:00
|
|
|
int eval_code_length, function_name_length, function_args_len, function_code_len;
|
2000-06-03 09:49:49 +08:00
|
|
|
int retval;
|
2000-09-13 03:47:25 +08:00
|
|
|
char *eval_name;
|
2000-06-03 09:49:49 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &function_args, &function_args_len, &function_code, &function_code_len) == FAILURE) {
|
|
|
|
return;
|
2000-06-03 09:49:49 +08:00
|
|
|
}
|
|
|
|
|
2009-06-06 02:50:32 +08:00
|
|
|
eval_code = (char *) emalloc(sizeof("function " LAMBDA_TEMP_FUNCNAME)
|
|
|
|
+function_args_len
|
|
|
|
+2 /* for the args parentheses */
|
|
|
|
+2 /* for the curly braces */
|
|
|
|
+function_code_len);
|
|
|
|
|
|
|
|
eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME "(") - 1;
|
|
|
|
memcpy(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(", eval_code_length);
|
|
|
|
|
|
|
|
memcpy(eval_code + eval_code_length, function_args, function_args_len);
|
|
|
|
eval_code_length += function_args_len;
|
|
|
|
|
|
|
|
eval_code[eval_code_length++] = ')';
|
|
|
|
eval_code[eval_code_length++] = '{';
|
|
|
|
|
|
|
|
memcpy(eval_code + eval_code_length, function_code, function_code_len);
|
|
|
|
eval_code_length += function_code_len;
|
|
|
|
|
|
|
|
eval_code[eval_code_length++] = '}';
|
|
|
|
eval_code[eval_code_length] = '\0';
|
2000-06-03 09:49:49 +08:00
|
|
|
|
2001-07-30 09:48:22 +08:00
|
|
|
eval_name = zend_make_compiled_string_description("runtime-created function" TSRMLS_CC);
|
2009-06-06 02:50:32 +08:00
|
|
|
retval = zend_eval_stringl(eval_code, eval_code_length, NULL, eval_name TSRMLS_CC);
|
2000-06-03 09:49:49 +08:00
|
|
|
efree(eval_code);
|
2000-09-13 03:47:25 +08:00
|
|
|
efree(eval_name);
|
|
|
|
|
2000-06-03 09:49:49 +08:00
|
|
|
if (retval==SUCCESS) {
|
2003-06-16 17:59:02 +08:00
|
|
|
zend_function new_function, *func;
|
2000-06-03 09:49:49 +08:00
|
|
|
|
|
|
|
if (zend_hash_find(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME), (void **) &func)==FAILURE) {
|
2000-06-05 14:52:02 +08:00
|
|
|
zend_error(E_ERROR, "Unexpected inconsistency in create_function()");
|
2000-06-03 09:49:49 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-06-16 17:59:02 +08:00
|
|
|
new_function = *func;
|
|
|
|
function_add_ref(&new_function);
|
2000-06-03 09:49:49 +08:00
|
|
|
|
|
|
|
function_name = (char *) emalloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG);
|
2009-06-06 02:50:32 +08:00
|
|
|
function_name[0] = '\0';
|
2000-06-03 09:49:49 +08:00
|
|
|
|
|
|
|
do {
|
2011-08-08 22:52:34 +08:00
|
|
|
function_name_length = 1 + snprintf(function_name + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count));
|
2003-06-16 17:59:02 +08:00
|
|
|
} while (zend_hash_add(EG(function_table), function_name, function_name_length+1, &new_function, sizeof(zend_function), NULL)==FAILURE);
|
2000-06-03 09:49:49 +08:00
|
|
|
zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME));
|
|
|
|
RETURN_STRINGL(function_name, function_name_length, 0);
|
|
|
|
} else {
|
2009-06-30 19:34:31 +08:00
|
|
|
zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME));
|
2000-06-03 09:49:49 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-06-05 14:52:02 +08:00
|
|
|
/* }}} */
|
2000-06-09 23:40:37 +08:00
|
|
|
|
|
|
|
|
2000-08-26 22:45:29 +08:00
|
|
|
#if ZEND_DEBUG
|
2000-06-09 23:40:37 +08:00
|
|
|
ZEND_FUNCTION(zend_test_func)
|
|
|
|
{
|
2000-06-10 09:08:55 +08:00
|
|
|
zval *arg1, *arg2;
|
2000-06-09 23:40:37 +08:00
|
|
|
|
2000-06-10 09:08:55 +08:00
|
|
|
zend_get_parameters(ht, 2, &arg1, &arg2);
|
2000-06-09 23:40:37 +08:00
|
|
|
}
|
2002-09-18 22:08:07 +08:00
|
|
|
|
|
|
|
|
2002-09-28 23:12:41 +08:00
|
|
|
#ifdef ZTS
|
2002-09-18 22:08:07 +08:00
|
|
|
ZEND_FUNCTION(zend_thread_id)
|
|
|
|
{
|
2008-07-25 04:44:15 +08:00
|
|
|
RETURN_LONG((long)tsrm_thread_id());
|
2002-09-18 22:08:07 +08:00
|
|
|
}
|
2000-08-26 22:45:29 +08:00
|
|
|
#endif
|
2002-09-28 23:12:41 +08:00
|
|
|
#endif
|
2000-07-15 04:00:24 +08:00
|
|
|
|
2002-03-02 21:48:13 +08:00
|
|
|
/* {{{ proto string get_resource_type(resource res)
|
|
|
|
Get the resource type name for a given resource */
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_FUNCTION(get_resource_type)
|
|
|
|
{
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *resource_type;
|
2008-06-19 07:38:37 +08:00
|
|
|
zval *z_resource_type;
|
2000-07-15 04:00:24 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_resource_type) == FAILURE) {
|
|
|
|
return;
|
2000-07-15 04:00:24 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
resource_type = zend_rsrc_list_get_rsrc_type(Z_LVAL_P(z_resource_type) TSRMLS_CC);
|
2000-07-15 04:00:24 +08:00
|
|
|
if (resource_type) {
|
|
|
|
RETURN_STRING(resource_type, 1);
|
|
|
|
} else {
|
|
|
|
RETURN_STRING("Unknown", 1);
|
|
|
|
}
|
|
|
|
}
|
2002-03-02 21:48:13 +08:00
|
|
|
/* }}} */
|
2001-05-21 23:47:52 +08:00
|
|
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
static int add_extension_info(zend_module_entry *module, void *arg TSRMLS_DC)
|
2001-05-21 23:47:52 +08:00
|
|
|
{
|
|
|
|
zval *name_array = (zval *)arg;
|
|
|
|
add_next_index_string(name_array, module->name, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-01 06:47:25 +08:00
|
|
|
static int add_zendext_info(zend_extension *ext, void *arg TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zval *name_array = (zval *)arg;
|
|
|
|
add_next_index_string(name_array, ext->name, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
static int add_constant_info(zend_constant *constant, void *arg TSRMLS_DC)
|
2001-05-21 23:47:52 +08:00
|
|
|
{
|
|
|
|
zval *name_array = (zval *)arg;
|
2001-05-23 21:54:22 +08:00
|
|
|
zval *const_val;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(const_val);
|
|
|
|
*const_val = constant->value;
|
|
|
|
zval_copy_ctor(const_val);
|
|
|
|
INIT_PZVAL(const_val);
|
|
|
|
add_assoc_zval_ex(name_array, constant->name, constant->name_len, const_val);
|
2001-05-21 23:47:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 01:58:32 +08:00
|
|
|
|
2007-08-03 00:54:44 +08:00
|
|
|
/* {{{ proto array get_loaded_extensions([bool zend_extensions]) U
|
2001-05-21 23:47:52 +08:00
|
|
|
Return an array containing names of loaded extensions */
|
|
|
|
ZEND_FUNCTION(get_loaded_extensions)
|
|
|
|
{
|
2007-08-03 04:32:44 +08:00
|
|
|
zend_bool zendext = 0;
|
2007-08-01 06:47:25 +08:00
|
|
|
|
2007-08-03 00:54:44 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &zendext) == FAILURE) {
|
|
|
|
return;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2007-08-01 06:47:25 +08:00
|
|
|
|
2007-08-03 00:54:44 +08:00
|
|
|
if (zendext) {
|
|
|
|
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) add_zendext_info, return_value TSRMLS_CC);
|
2007-08-01 06:47:25 +08:00
|
|
|
} else {
|
|
|
|
zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) add_extension_info, return_value TSRMLS_CC);
|
|
|
|
}
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2009-05-07 20:08:09 +08:00
|
|
|
/* {{{ proto array get_defined_constants([bool categorize])
|
2001-05-21 23:47:52 +08:00
|
|
|
Return an array containing the names and values of all defined constants */
|
|
|
|
ZEND_FUNCTION(get_defined_constants)
|
|
|
|
{
|
2009-05-07 20:08:09 +08:00
|
|
|
zend_bool categorize = 0;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &categorize) == FAILURE) {
|
|
|
|
return;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2003-02-07 11:04:26 +08:00
|
|
|
|
2009-05-07 20:08:09 +08:00
|
|
|
if (categorize) {
|
2003-02-07 11:04:26 +08:00
|
|
|
HashPosition pos;
|
|
|
|
zend_constant *val;
|
2003-08-22 10:08:10 +08:00
|
|
|
int module_number;
|
|
|
|
zval **modules;
|
2008-01-25 02:07:45 +08:00
|
|
|
char **module_names;
|
2003-02-07 11:04:26 +08:00
|
|
|
zend_module_entry *module;
|
|
|
|
int i = 1;
|
2003-08-22 10:08:10 +08:00
|
|
|
|
|
|
|
modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval *));
|
|
|
|
module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2003-08-22 10:08:10 +08:00
|
|
|
module_names[0] = "internal";
|
2003-02-07 11:04:26 +08:00
|
|
|
zend_hash_internal_pointer_reset_ex(&module_registry, &pos);
|
2003-08-22 10:08:10 +08:00
|
|
|
while (zend_hash_get_current_data_ex(&module_registry, (void *) &module, &pos) != FAILURE) {
|
2009-03-04 07:42:51 +08:00
|
|
|
module_names[module->module_number] = (char *)module->name;
|
|
|
|
i++;
|
2003-02-07 11:04:26 +08:00
|
|
|
zend_hash_move_forward_ex(&module_registry, &pos);
|
|
|
|
}
|
2003-08-22 10:08:10 +08:00
|
|
|
module_names[i] = "user";
|
2003-02-07 11:04:26 +08:00
|
|
|
|
2003-08-22 10:08:10 +08:00
|
|
|
zend_hash_internal_pointer_reset_ex(EG(zend_constants), &pos);
|
2003-02-07 11:04:26 +08:00
|
|
|
while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &val, &pos) != FAILURE) {
|
|
|
|
zval *const_val;
|
|
|
|
|
2003-08-23 02:50:12 +08:00
|
|
|
if (val->module_number == PHP_USER_CONSTANT) {
|
2003-08-22 10:08:10 +08:00
|
|
|
module_number = i;
|
|
|
|
} else if (val->module_number > i || val->module_number < 0) {
|
|
|
|
/* should not happen */
|
|
|
|
goto bad_module_id;
|
|
|
|
} else {
|
|
|
|
module_number = val->module_number;
|
|
|
|
}
|
2003-02-07 11:04:26 +08:00
|
|
|
|
2003-08-22 10:08:10 +08:00
|
|
|
if (!modules[module_number]) {
|
|
|
|
MAKE_STD_ZVAL(modules[module_number]);
|
|
|
|
array_init(modules[module_number]);
|
|
|
|
add_assoc_zval(return_value, module_names[module_number], modules[module_number]);
|
|
|
|
}
|
2003-02-07 11:04:26 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(const_val);
|
|
|
|
*const_val = val->value;
|
|
|
|
zval_copy_ctor(const_val);
|
|
|
|
INIT_PZVAL(const_val);
|
|
|
|
|
2003-08-22 10:08:10 +08:00
|
|
|
add_assoc_zval_ex(modules[module_number], val->name, val->name_len, const_val);
|
|
|
|
bad_module_id:
|
2003-02-07 11:04:26 +08:00
|
|
|
zend_hash_move_forward_ex(EG(zend_constants), &pos);
|
|
|
|
}
|
|
|
|
efree(module_names);
|
2003-08-22 10:08:10 +08:00
|
|
|
efree(modules);
|
2003-02-07 11:04:26 +08:00
|
|
|
} else {
|
|
|
|
zend_hash_apply_with_argument(EG(zend_constants), (apply_func_arg_t) add_constant_info, return_value TSRMLS_CC);
|
|
|
|
}
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
2002-07-05 10:34:54 +08:00
|
|
|
/* }}} */
|
2001-05-21 23:47:52 +08:00
|
|
|
|
|
|
|
|
2008-01-24 17:41:39 +08:00
|
|
|
static zval *debug_backtrace_get_args(void **curpos TSRMLS_DC)
|
2004-02-26 05:06:59 +08:00
|
|
|
{
|
2008-01-24 17:41:39 +08:00
|
|
|
void **p = curpos;
|
2002-08-23 22:22:25 +08:00
|
|
|
zval *arg_array, **arg;
|
2007-04-16 16:09:56 +08:00
|
|
|
int arg_count = (int)(zend_uintptr_t) *p;
|
2002-08-23 22:22:25 +08:00
|
|
|
|
2002-08-27 00:40:34 +08:00
|
|
|
MAKE_STD_ZVAL(arg_array);
|
2008-05-27 18:29:33 +08:00
|
|
|
array_init_size(arg_array, arg_count);
|
2002-08-27 00:40:34 +08:00
|
|
|
p -= arg_count;
|
2002-08-28 22:49:15 +08:00
|
|
|
|
2002-08-27 00:40:34 +08:00
|
|
|
while (--arg_count >= 0) {
|
|
|
|
arg = (zval **) p++;
|
2006-05-31 21:01:57 +08:00
|
|
|
if (*arg) {
|
2006-11-16 01:53:27 +08:00
|
|
|
if (Z_TYPE_PP(arg) != IS_OBJECT) {
|
2006-11-16 00:05:11 +08:00
|
|
|
SEPARATE_ZVAL_TO_MAKE_IS_REF(arg);
|
|
|
|
}
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_PP(arg);
|
2006-05-31 21:01:57 +08:00
|
|
|
add_next_index_zval(arg_array, *arg);
|
|
|
|
} else {
|
|
|
|
add_next_index_null(arg_array);
|
|
|
|
}
|
2002-08-23 22:22:25 +08:00
|
|
|
}
|
2005-06-23 20:00:13 +08:00
|
|
|
|
2002-08-27 00:40:34 +08:00
|
|
|
return arg_array;
|
2002-08-23 22:22:25 +08:00
|
|
|
}
|
|
|
|
|
2003-01-12 22:25:58 +08:00
|
|
|
void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
|
2002-12-02 03:47:02 +08:00
|
|
|
{
|
|
|
|
zval **tmp;
|
|
|
|
HashPosition iterator;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
zend_hash_internal_pointer_reset_ex(arg_array->value.ht, &iterator);
|
|
|
|
while (zend_hash_get_current_data_ex(arg_array->value.ht, (void **) &tmp, &iterator) == SUCCESS) {
|
|
|
|
if (i++) {
|
|
|
|
ZEND_PUTS(", ");
|
|
|
|
}
|
2003-01-12 22:25:58 +08:00
|
|
|
zend_print_flat_zval_r(*tmp TSRMLS_CC);
|
2002-12-02 03:47:02 +08:00
|
|
|
zend_hash_move_forward_ex(arg_array->value.ht, &iterator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
|
2002-12-02 03:47:02 +08:00
|
|
|
ZEND_FUNCTION(debug_print_backtrace)
|
|
|
|
{
|
2005-06-22 23:26:05 +08:00
|
|
|
zend_execute_data *ptr, *skip;
|
2011-04-09 17:52:24 +08:00
|
|
|
int lineno, frameno = 0;
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *function_name;
|
|
|
|
const char *filename;
|
2010-10-15 05:33:10 +08:00
|
|
|
const char *class_name = NULL;
|
2002-12-02 03:47:02 +08:00
|
|
|
char *call_type;
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *include_filename = NULL;
|
2003-01-09 00:41:47 +08:00
|
|
|
zval *arg_array = NULL;
|
2003-01-12 20:57:20 +08:00
|
|
|
int indent = 0;
|
2011-01-17 04:39:22 +08:00
|
|
|
long options = 0;
|
2011-04-09 17:52:24 +08:00
|
|
|
long limit = 0;
|
2002-12-02 03:47:02 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &options, &limit) == FAILURE) {
|
2008-03-11 06:02:41 +08:00
|
|
|
return;
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = EG(current_execute_data);
|
|
|
|
|
|
|
|
/* skip debug_backtrace() */
|
|
|
|
ptr = ptr->prev_execute_data;
|
2005-06-23 20:00:13 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
while (ptr && (limit == 0 || frameno < limit)) {
|
2010-10-15 05:33:10 +08:00
|
|
|
const char *free_class_name = NULL;
|
2005-06-07 21:14:23 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
frameno++;
|
2005-06-07 21:14:23 +08:00
|
|
|
class_name = call_type = NULL;
|
2005-02-02 03:05:56 +08:00
|
|
|
arg_array = NULL;
|
2005-06-22 23:26:05 +08:00
|
|
|
|
|
|
|
skip = ptr;
|
2006-05-10 07:53:23 +08:00
|
|
|
/* skip internal handler */
|
2005-06-22 23:26:05 +08:00
|
|
|
if (!skip->op_array &&
|
|
|
|
skip->prev_execute_data &&
|
|
|
|
skip->prev_execute_data->opline &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
|
2008-01-24 17:41:39 +08:00
|
|
|
skip = skip->prev_execute_data;
|
2005-06-22 23:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (skip->op_array) {
|
|
|
|
filename = skip->op_array->filename;
|
|
|
|
lineno = skip->opline->lineno;
|
2002-12-02 03:47:02 +08:00
|
|
|
} else {
|
|
|
|
filename = NULL;
|
2003-08-29 00:41:20 +08:00
|
|
|
lineno = 0;
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function_name = ptr->function_state.function->common.function_name;
|
|
|
|
|
|
|
|
if (function_name) {
|
|
|
|
if (ptr->object) {
|
2005-06-23 17:23:24 +08:00
|
|
|
if (ptr->function_state.function->common.scope) {
|
|
|
|
class_name = ptr->function_state.function->common.scope->name;
|
2005-06-07 21:14:23 +08:00
|
|
|
} else {
|
2005-06-23 17:23:24 +08:00
|
|
|
zend_uint class_name_len;
|
2005-06-28 02:13:13 +08:00
|
|
|
int dup;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2005-06-28 02:13:13 +08:00
|
|
|
dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC);
|
|
|
|
if(!dup) {
|
2005-06-23 17:23:24 +08:00
|
|
|
free_class_name = class_name;
|
|
|
|
}
|
2005-04-05 01:23:38 +08:00
|
|
|
}
|
2005-06-28 02:13:13 +08:00
|
|
|
|
2002-12-02 03:47:02 +08:00
|
|
|
call_type = "->";
|
|
|
|
} else if (ptr->function_state.function->common.scope) {
|
|
|
|
class_name = ptr->function_state.function->common.scope->name;
|
|
|
|
call_type = "::";
|
|
|
|
} else {
|
|
|
|
class_name = NULL;
|
|
|
|
call_type = NULL;
|
|
|
|
}
|
|
|
|
if ((! ptr->opline) || ((ptr->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (ptr->opline->opcode == ZEND_DO_FCALL))) {
|
2011-01-17 04:39:22 +08:00
|
|
|
if (ptr->function_state.arguments && (options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) {
|
2008-01-24 17:41:39 +08:00
|
|
|
arg_array = debug_backtrace_get_args(ptr->function_state.arguments TSRMLS_CC);
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
}
|
2002-12-02 03:47:02 +08:00
|
|
|
} else {
|
|
|
|
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
|
|
|
|
zend_bool build_filename_arg = 1;
|
|
|
|
|
2005-06-27 14:03:10 +08:00
|
|
|
if (!ptr->opline || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
|
|
|
|
/* can happen when calling eval from a custom sapi */
|
|
|
|
function_name = "unknown";
|
|
|
|
build_filename_arg = 0;
|
|
|
|
} else
|
2010-04-20 18:57:45 +08:00
|
|
|
switch (ptr->opline->extended_value) {
|
2002-12-02 03:47:02 +08:00
|
|
|
case ZEND_EVAL:
|
|
|
|
function_name = "eval";
|
|
|
|
build_filename_arg = 0;
|
|
|
|
break;
|
|
|
|
case ZEND_INCLUDE:
|
|
|
|
function_name = "include";
|
|
|
|
break;
|
|
|
|
case ZEND_REQUIRE:
|
|
|
|
function_name = "require";
|
|
|
|
break;
|
|
|
|
case ZEND_INCLUDE_ONCE:
|
|
|
|
function_name = "include_once";
|
|
|
|
break;
|
|
|
|
case ZEND_REQUIRE_ONCE:
|
|
|
|
function_name = "require_once";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* this can actually happen if you use debug_backtrace() in your error_handler and
|
|
|
|
* you're in the top-scope */
|
|
|
|
function_name = "unknown";
|
|
|
|
build_filename_arg = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (build_filename_arg && include_filename) {
|
|
|
|
MAKE_STD_ZVAL(arg_array);
|
|
|
|
array_init(arg_array);
|
2011-09-13 21:29:35 +08:00
|
|
|
add_next_index_string(arg_array, (char*)include_filename, 1);
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
2003-08-29 00:41:20 +08:00
|
|
|
call_type = NULL;
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
|
|
|
zend_printf("#%-2d ", indent);
|
|
|
|
if (class_name) {
|
|
|
|
ZEND_PUTS(class_name);
|
|
|
|
ZEND_PUTS(call_type);
|
|
|
|
}
|
2011-08-07 14:19:43 +08:00
|
|
|
zend_printf("%s(", function_name);
|
2003-01-09 00:41:47 +08:00
|
|
|
if (arg_array) {
|
2003-01-12 22:25:58 +08:00
|
|
|
debug_print_backtrace_args(arg_array TSRMLS_CC);
|
2003-01-09 00:41:47 +08:00
|
|
|
zval_ptr_dtor(&arg_array);
|
|
|
|
}
|
2006-03-03 18:09:21 +08:00
|
|
|
if (filename) {
|
|
|
|
zend_printf(") called at [%s:%d]\n", filename, lineno);
|
|
|
|
} else {
|
2006-07-27 16:20:38 +08:00
|
|
|
zend_execute_data *prev = skip->prev_execute_data;
|
|
|
|
|
|
|
|
while (prev) {
|
|
|
|
if (prev->function_state.function &&
|
|
|
|
prev->function_state.function->common.type != ZEND_USER_FUNCTION) {
|
|
|
|
prev = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (prev->op_array) {
|
|
|
|
zend_printf(") called at [%s:%d]\n", prev->op_array->filename, prev->opline->lineno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = prev->prev_execute_data;
|
|
|
|
}
|
|
|
|
if (!prev) {
|
|
|
|
ZEND_PUTS(")\n");
|
|
|
|
}
|
2006-03-03 18:09:21 +08:00
|
|
|
}
|
2004-09-10 00:47:22 +08:00
|
|
|
include_filename = filename;
|
2005-06-22 23:26:05 +08:00
|
|
|
ptr = skip->prev_execute_data;
|
2002-12-02 03:47:02 +08:00
|
|
|
++indent;
|
2005-06-07 21:14:23 +08:00
|
|
|
if (free_class_name) {
|
2011-09-13 21:29:35 +08:00
|
|
|
efree((char*)free_class_name);
|
2005-06-07 21:14:23 +08:00
|
|
|
}
|
2002-12-02 03:47:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
2003-08-29 04:35:54 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit TSRMLS_DC)
|
2002-05-03 01:20:48 +08:00
|
|
|
{
|
2005-06-22 23:26:05 +08:00
|
|
|
zend_execute_data *ptr, *skip;
|
2011-04-09 17:52:24 +08:00
|
|
|
int lineno, frameno = 0;
|
2011-09-13 21:29:35 +08:00
|
|
|
const char *function_name;
|
|
|
|
const char *filename;
|
|
|
|
const char *class_name;
|
|
|
|
const char *include_filename = NULL;
|
2002-05-10 17:41:50 +08:00
|
|
|
zval *stack_frame;
|
2002-09-02 20:20:09 +08:00
|
|
|
|
2002-05-03 01:20:48 +08:00
|
|
|
ptr = EG(current_execute_data);
|
2002-07-26 18:38:25 +08:00
|
|
|
|
2005-06-22 23:26:05 +08:00
|
|
|
/* skip "new Exception()" */
|
2005-08-22 21:26:33 +08:00
|
|
|
if (ptr && (skip_last == 0) && ptr->opline && (ptr->opline->opcode == ZEND_NEW)) {
|
2005-06-22 23:26:05 +08:00
|
|
|
ptr = ptr->prev_execute_data;
|
|
|
|
}
|
|
|
|
|
2004-02-26 05:06:59 +08:00
|
|
|
/* skip debug_backtrace() */
|
2006-11-29 05:20:33 +08:00
|
|
|
if (skip_last-- && ptr) {
|
2005-06-22 23:26:05 +08:00
|
|
|
ptr = ptr->prev_execute_data;
|
2003-08-29 08:16:00 +08:00
|
|
|
}
|
2002-08-27 00:40:34 +08:00
|
|
|
|
2002-05-10 17:41:50 +08:00
|
|
|
array_init(return_value);
|
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
while (ptr && (limit == 0 || frameno < limit)) {
|
|
|
|
frameno++;
|
2002-05-10 17:41:50 +08:00
|
|
|
MAKE_STD_ZVAL(stack_frame);
|
|
|
|
array_init(stack_frame);
|
|
|
|
|
2005-06-22 23:26:05 +08:00
|
|
|
skip = ptr;
|
|
|
|
/* skip internal handler */
|
|
|
|
if (!skip->op_array &&
|
|
|
|
skip->prev_execute_data &&
|
|
|
|
skip->prev_execute_data->opline &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
|
|
|
|
skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
|
2006-07-27 16:20:38 +08:00
|
|
|
skip = skip->prev_execute_data;
|
2005-06-22 23:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (skip->op_array) {
|
|
|
|
filename = skip->op_array->filename;
|
|
|
|
lineno = skip->opline->lineno;
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "file", sizeof("file"), (char*)filename, 1);
|
2002-08-23 21:50:42 +08:00
|
|
|
add_assoc_long_ex(stack_frame, "line", sizeof("line"), lineno);
|
2002-08-28 22:49:15 +08:00
|
|
|
|
|
|
|
/* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function
|
|
|
|
* and debug_baktrace() might have been called by the error_handler. in this case we don't
|
|
|
|
* want to pop anything of the argument-stack */
|
2002-08-27 00:40:34 +08:00
|
|
|
} else {
|
2006-07-27 16:20:38 +08:00
|
|
|
zend_execute_data *prev = skip->prev_execute_data;
|
|
|
|
|
|
|
|
while (prev) {
|
|
|
|
if (prev->function_state.function &&
|
2010-03-07 10:17:11 +08:00
|
|
|
prev->function_state.function->common.type != ZEND_USER_FUNCTION &&
|
|
|
|
!(prev->function_state.function->common.type == ZEND_INTERNAL_FUNCTION &&
|
|
|
|
(prev->function_state.function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER))) {
|
2006-07-27 16:20:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (prev->op_array) {
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "file", sizeof("file"), (char*)prev->op_array->filename, 1);
|
2006-07-27 16:20:38 +08:00
|
|
|
add_assoc_long_ex(stack_frame, "line", sizeof("line"), prev->opline->lineno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = prev->prev_execute_data;
|
|
|
|
}
|
2002-08-27 00:40:34 +08:00
|
|
|
filename = NULL;
|
2002-08-23 21:50:42 +08:00
|
|
|
}
|
2002-05-10 17:41:50 +08:00
|
|
|
|
2002-08-23 22:44:58 +08:00
|
|
|
function_name = ptr->function_state.function->common.function_name;
|
|
|
|
|
2002-07-26 18:38:25 +08:00
|
|
|
if (function_name) {
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
|
2002-08-23 21:50:42 +08:00
|
|
|
|
2005-03-08 03:28:10 +08:00
|
|
|
if (ptr->object && Z_TYPE_P(ptr->object) == IS_OBJECT) {
|
2005-06-23 17:23:24 +08:00
|
|
|
if (ptr->function_state.function->common.scope) {
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1);
|
2005-04-18 15:25:20 +08:00
|
|
|
} else {
|
2005-06-23 17:23:24 +08:00
|
|
|
zend_uint class_name_len;
|
2005-06-28 02:13:13 +08:00
|
|
|
int dup;
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2005-06-28 02:13:13 +08:00
|
|
|
dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC);
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)class_name, dup);
|
2005-06-28 02:13:13 +08:00
|
|
|
|
2005-04-05 01:23:38 +08:00
|
|
|
}
|
2011-01-17 04:39:22 +08:00
|
|
|
if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
|
2005-11-24 13:07:28 +08:00
|
|
|
add_assoc_zval_ex(stack_frame, "object", sizeof("object"), ptr->object);
|
2007-10-07 13:22:07 +08:00
|
|
|
Z_ADDREF_P(ptr->object);
|
2005-11-24 13:07:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-18 15:25:20 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "type", sizeof("type"), "->", 1);
|
2002-08-28 22:49:15 +08:00
|
|
|
} else if (ptr->function_state.function->common.scope) {
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1);
|
2005-04-18 15:25:20 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "type", sizeof("type"), "::", 1);
|
2002-08-23 22:44:58 +08:00
|
|
|
}
|
|
|
|
|
2011-01-17 04:39:22 +08:00
|
|
|
if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 &&
|
|
|
|
((! ptr->opline) || ((ptr->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (ptr->opline->opcode == ZEND_DO_FCALL)))) {
|
2008-01-24 17:41:39 +08:00
|
|
|
if (ptr->function_state.arguments) {
|
|
|
|
add_assoc_zval_ex(stack_frame, "args", sizeof("args"), debug_backtrace_get_args(ptr->function_state.arguments TSRMLS_CC));
|
2002-09-02 20:26:09 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
}
|
2002-08-23 22:44:58 +08:00
|
|
|
} else {
|
|
|
|
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
|
2002-08-27 00:40:34 +08:00
|
|
|
zend_bool build_filename_arg = 1;
|
2002-08-23 22:44:58 +08:00
|
|
|
|
2005-06-27 14:03:10 +08:00
|
|
|
if (!ptr->opline || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
|
2004-07-27 09:33:25 +08:00
|
|
|
/* can happen when calling eval from a custom sapi */
|
|
|
|
function_name = "unknown";
|
|
|
|
build_filename_arg = 0;
|
|
|
|
} else
|
2010-04-20 18:57:45 +08:00
|
|
|
switch (ptr->opline->extended_value) {
|
2002-08-25 04:52:52 +08:00
|
|
|
case ZEND_EVAL:
|
|
|
|
function_name = "eval";
|
2002-08-27 00:40:34 +08:00
|
|
|
build_filename_arg = 0;
|
2002-08-25 04:52:52 +08:00
|
|
|
break;
|
|
|
|
case ZEND_INCLUDE:
|
|
|
|
function_name = "include";
|
|
|
|
break;
|
|
|
|
case ZEND_REQUIRE:
|
|
|
|
function_name = "require";
|
|
|
|
break;
|
|
|
|
case ZEND_INCLUDE_ONCE:
|
|
|
|
function_name = "include_once";
|
|
|
|
break;
|
|
|
|
case ZEND_REQUIRE_ONCE:
|
|
|
|
function_name = "require_once";
|
|
|
|
break;
|
|
|
|
default:
|
2002-08-28 22:49:15 +08:00
|
|
|
/* this can actually happen if you use debug_backtrace() in your error_handler and
|
|
|
|
* you're in the top-scope */
|
|
|
|
function_name = "unknown";
|
2002-08-27 00:40:34 +08:00
|
|
|
build_filename_arg = 0;
|
2002-08-25 04:52:52 +08:00
|
|
|
break;
|
2002-08-24 17:05:44 +08:00
|
|
|
}
|
|
|
|
|
2002-08-27 00:40:34 +08:00
|
|
|
if (build_filename_arg && include_filename) {
|
|
|
|
zval *arg_array;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(arg_array);
|
|
|
|
array_init(arg_array);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2002-08-27 00:40:34 +08:00
|
|
|
/* include_filename always points to the last filename of the last last called-fuction.
|
|
|
|
if we have called include in the frame above - this is the file we have included.
|
2002-08-24 17:05:44 +08:00
|
|
|
*/
|
2002-08-27 00:40:34 +08:00
|
|
|
|
2011-09-13 21:29:35 +08:00
|
|
|
add_next_index_string(arg_array, (char*)include_filename, 1);
|
2002-08-27 00:40:34 +08:00
|
|
|
add_assoc_zval_ex(stack_frame, "args", sizeof("args"), arg_array);
|
2002-08-23 22:44:58 +08:00
|
|
|
}
|
2002-08-23 21:50:42 +08:00
|
|
|
|
2011-09-13 21:29:35 +08:00
|
|
|
add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
|
2002-08-23 22:44:58 +08:00
|
|
|
}
|
2002-08-23 22:22:25 +08:00
|
|
|
|
2002-07-26 18:38:25 +08:00
|
|
|
add_next_index_zval(return_value, stack_frame);
|
|
|
|
|
2004-09-10 00:47:22 +08:00
|
|
|
include_filename = filename;
|
2002-08-27 00:40:34 +08:00
|
|
|
|
2005-06-22 23:26:05 +08:00
|
|
|
ptr = skip->prev_execute_data;
|
2002-05-03 01:20:48 +08:00
|
|
|
}
|
|
|
|
}
|
2002-07-05 10:34:54 +08:00
|
|
|
/* }}} */
|
2002-05-03 01:20:48 +08:00
|
|
|
|
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
/* {{{ proto array debug_backtrace([int options[, int limit]])
|
2003-08-29 04:35:54 +08:00
|
|
|
Return backtrace as array */
|
|
|
|
ZEND_FUNCTION(debug_backtrace)
|
|
|
|
{
|
2011-01-17 04:39:22 +08:00
|
|
|
long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
|
2011-04-09 17:52:24 +08:00
|
|
|
long limit = 0;
|
2007-08-30 15:43:21 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &options, &limit) == FAILURE) {
|
2007-08-30 15:43:21 +08:00
|
|
|
return;
|
2003-08-29 04:35:54 +08:00
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2011-04-09 17:52:24 +08:00
|
|
|
zend_fetch_debug_backtrace(return_value, 1, options, limit TSRMLS_CC);
|
2003-08-29 04:35:54 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-05-21 23:47:52 +08:00
|
|
|
/* {{{ proto bool extension_loaded(string extension_name)
|
|
|
|
Returns true if the named extension is loaded */
|
|
|
|
ZEND_FUNCTION(extension_loaded)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *extension_name;
|
|
|
|
int extension_name_len;
|
2004-03-30 02:48:59 +08:00
|
|
|
char *lcname;
|
2001-05-21 23:47:52 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension_name, &extension_name_len) == FAILURE) {
|
|
|
|
return;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
lcname = zend_str_tolower_dup(extension_name, extension_name_len);
|
|
|
|
if (zend_hash_exists(&module_registry, lcname, extension_name_len+1)) {
|
2004-03-30 02:48:59 +08:00
|
|
|
RETVAL_TRUE;
|
2001-05-21 23:47:52 +08:00
|
|
|
} else {
|
2004-03-30 02:48:59 +08:00
|
|
|
RETVAL_FALSE;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
2004-03-30 02:48:59 +08:00
|
|
|
efree(lcname);
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto array get_extension_funcs(string extension_name)
|
|
|
|
Returns an array with the names of functions belonging to the named extension */
|
|
|
|
ZEND_FUNCTION(get_extension_funcs)
|
|
|
|
{
|
2008-06-19 07:38:37 +08:00
|
|
|
char *extension_name;
|
|
|
|
int extension_name_len;
|
2001-05-21 23:47:52 +08:00
|
|
|
zend_module_entry *module;
|
2007-09-28 02:00:48 +08:00
|
|
|
const zend_function_entry *func;
|
2001-05-21 23:47:52 +08:00
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension_name, &extension_name_len) == FAILURE) {
|
|
|
|
return;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
|
2008-06-19 07:38:37 +08:00
|
|
|
if (strncasecmp(extension_name, "zend", sizeof("zend"))) {
|
|
|
|
char *lcname = zend_str_tolower_dup(extension_name, extension_name_len);
|
2005-03-13 23:30:10 +08:00
|
|
|
if (zend_hash_find(&module_registry, lcname,
|
2008-06-19 07:38:37 +08:00
|
|
|
extension_name_len+1, (void**)&module) == FAILURE) {
|
2005-03-14 17:21:04 +08:00
|
|
|
efree(lcname);
|
2003-02-07 04:21:02 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2005-03-14 17:21:04 +08:00
|
|
|
efree(lcname);
|
2006-05-10 07:53:23 +08:00
|
|
|
|
2003-02-07 04:21:02 +08:00
|
|
|
if (!(func = module->functions)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
func = builtin_functions;
|
2001-05-21 23:47:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2001-06-26 23:19:47 +08:00
|
|
|
|
2001-05-21 23:47:52 +08:00
|
|
|
while (func->fname) {
|
|
|
|
add_next_index_string(return_value, func->fname, 1);
|
|
|
|
func++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2002-08-16 08:41:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|