php-src/Zend/zend_builtin_functions.c

2234 lines
60 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
2019-01-30 09:23:29 +00:00
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
2001-12-11 15:16:21 +00:00
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
2001-12-11 15:16:21 +00:00
| http://www.zend.com/license/2_00.txt. |
| 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@php.net> |
| Zeev Suraski <zeev@php.net> |
+----------------------------------------------------------------------+
*/
#include "zend.h"
#include "zend_API.h"
#include "zend_gc.h"
#include "zend_builtin_functions.h"
#include "zend_constants.h"
2002-11-19 17:51:30 +00:00
#include "zend_ini.h"
#include "zend_exceptions.h"
#include "zend_extensions.h"
#include "zend_closures.h"
2015-03-06 23:28:12 +00:00
#include "zend_generators.h"
#include "zend_builtin_functions_arginfo.h"
2015-02-04 17:21:42 +00:00
2016-01-21 06:31:03 +00:00
/* }}} */
ZEND_MINIT_FUNCTION(core) { /* {{{ */
zend_class_entry class_entry;
INIT_CLASS_ENTRY(class_entry, "stdClass", NULL);
2014-12-13 22:06:14 +00:00
zend_standard_class_def = zend_register_internal_class(&class_entry);
2014-12-13 22:06:14 +00:00
zend_register_default_classes();
return SUCCESS;
}
/* }}} */
zend_module_entry zend_builtin_module = { /* {{{ */
STANDARD_MODULE_HEADER,
"Core",
ext_functions,
ZEND_MINIT(core),
NULL,
NULL,
NULL,
NULL,
ZEND_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
2014-12-13 22:06:14 +00:00
int zend_startup_builtin_functions(void) /* {{{ */
{
zend_builtin_module.module_number = 0;
zend_builtin_module.type = MODULE_PERSISTENT;
2014-12-13 22:06:14 +00:00
return (EG(current_module) = zend_register_module_ex(&zend_builtin_module)) == NULL ? FAILURE : SUCCESS;
}
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto string zend_version(void)
Get the version of the Zend Engine */
ZEND_FUNCTION(zend_version)
{
ZEND_PARSE_PARAMETERS_NONE();
RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1);
}
2001-12-04 17:58:32 +00:00
/* }}} */
/* {{{ proto int gc_mem_caches(void)
Reclaims memory used by MM caches.
Returns number of freed bytes */
ZEND_FUNCTION(gc_mem_caches)
{
ZEND_PARSE_PARAMETERS_NONE();
RETURN_LONG(zend_mm_gc(zend_mm_get_heap()));
}
/* }}} */
2008-01-22 09:27:48 +00:00
/* {{{ proto int gc_collect_cycles(void)
Forces collection of any existing garbage cycles.
Returns number of freed zvals */
ZEND_FUNCTION(gc_collect_cycles)
{
ZEND_PARSE_PARAMETERS_NONE();
2014-12-13 22:06:14 +00:00
RETURN_LONG(gc_collect_cycles());
2008-01-22 09:27:48 +00:00
}
/* }}} */
/* {{{ proto void gc_enabled(void)
Returns status of the circular reference collector */
ZEND_FUNCTION(gc_enabled)
{
ZEND_PARSE_PARAMETERS_NONE();
RETURN_BOOL(gc_enabled());
2008-01-22 09:27:48 +00:00
}
/* }}} */
/* {{{ proto void gc_enable(void)
Activates the circular reference collector */
ZEND_FUNCTION(gc_enable)
{
zend_string *key;
ZEND_PARSE_PARAMETERS_NONE();
key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
zend_alter_ini_entry_chars(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
zend_string_release_ex(key, 0);
2008-01-22 09:27:48 +00:00
}
/* }}} */
/* {{{ proto void gc_disable(void)
Deactivates the circular reference collector */
ZEND_FUNCTION(gc_disable)
{
zend_string *key;
ZEND_PARSE_PARAMETERS_NONE();
key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
zend_alter_ini_entry_chars(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
zend_string_release_ex(key, 0);
2008-01-22 09:27:48 +00:00
}
/* }}} */
/* {{{ proto array gc_status(void)
Returns current GC statistics */
ZEND_FUNCTION(gc_status)
{
zend_gc_status status;
ZEND_PARSE_PARAMETERS_NONE();
zend_gc_get_status(&status);
array_init_size(return_value, 3);
2018-06-13 08:28:24 +00:00
add_assoc_long_ex(return_value, "runs", sizeof("runs")-1, (long)status.runs);
add_assoc_long_ex(return_value, "collected", sizeof("collected")-1, (long)status.collected);
2018-06-13 08:28:24 +00:00
add_assoc_long_ex(return_value, "threshold", sizeof("threshold")-1, (long)status.threshold);
2018-06-13 08:41:51 +00:00
add_assoc_long_ex(return_value, "roots", sizeof("roots")-1, (long)status.num_roots);
}
2018-06-13 08:41:51 +00:00
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto int func_num_args(void)
Get the number of arguments that were passed to the function */
1999-09-21 07:31:24 +00:00
ZEND_FUNCTION(func_num_args)
{
zend_execute_data *ex = EX(prev_execute_data);
ZEND_PARSE_PARAMETERS_NONE();
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
1999-09-21 07:31:24 +00:00
zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context");
2014-08-25 17:24:55 +00:00
RETURN_LONG(-1);
}
if (zend_forbid_dynamic_call("func_num_args()") == FAILURE) {
RETURN_LONG(-1);
}
RETURN_LONG(ZEND_CALL_NUM_ARGS(ex));
}
2001-12-04 17:58:32 +00:00
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto mixed func_get_arg(int arg_num)
Get the $arg_num'th argument that was passed to the function */
1999-09-21 07:31:24 +00:00
ZEND_FUNCTION(func_get_arg)
{
2014-09-15 10:08:42 +00:00
uint32_t arg_count, first_extra_arg;
zval *arg;
2014-08-25 17:24:55 +00:00
zend_long requested_offset;
zend_execute_data *ex;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) == FAILURE) {
RETURN_THROWS();
}
2002-05-08 14:10:30 +00:00
if (requested_offset < 0) {
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
2002-05-08 14:10:30 +00:00
}
ex = EX(prev_execute_data);
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
RETURN_THROWS();
}
if (zend_forbid_dynamic_call("func_get_arg()") == FAILURE) {
RETURN_THROWS();
}
arg_count = ZEND_CALL_NUM_ARGS(ex);
2016-04-29 11:44:56 +00:00
if ((zend_ulong)requested_offset >= arg_count) {
zend_throw_error(NULL, "func_get_arg(): Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
RETURN_THROWS();
}
first_extra_arg = ex->func->op_array.num_args;
2016-04-29 11:44:56 +00:00
if ((zend_ulong)requested_offset >= first_extra_arg && (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) {
arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T) + (requested_offset - first_extra_arg);
} else {
arg = ZEND_CALL_ARG(ex, requested_offset + 1);
}
if (EXPECTED(!Z_ISUNDEF_P(arg))) {
ZVAL_COPY_DEREF(return_value, arg);
}
}
2001-12-04 17:58:32 +00:00
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto array func_get_args()
Get an array of the arguments that were passed to the function */
1999-09-21 07:31:24 +00:00
ZEND_FUNCTION(func_get_args)
{
zval *p, *q;
2014-09-15 10:08:42 +00:00
uint32_t arg_count, first_extra_arg;
uint32_t i;
zend_execute_data *ex = EX(prev_execute_data);
1999-09-21 07:31:24 +00:00
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
RETURN_THROWS();
1999-09-21 07:31:24 +00:00
}
if (zend_forbid_dynamic_call("func_get_args()") == FAILURE) {
RETURN_THROWS();
}
arg_count = ZEND_CALL_NUM_ARGS(ex);
1999-09-21 07:31:24 +00:00
if (arg_count) {
array_init_size(return_value, arg_count);
first_extra_arg = ex->func->op_array.num_args;
2018-03-22 21:13:45 +00:00
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
i = 0;
p = ZEND_CALL_ARG(ex, 1);
2015-01-20 05:55:36 +00:00
if (arg_count > first_extra_arg) {
while (i < first_extra_arg) {
q = p;
if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
ZVAL_DEREF(q);
if (Z_OPT_REFCOUNTED_P(q)) {
Z_ADDREF_P(q);
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET(q);
} else {
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET_NULL();
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_NEXT();
p++;
i++;
}
p = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T);
}
while (i < arg_count) {
q = p;
if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
ZVAL_DEREF(q);
if (Z_OPT_REFCOUNTED_P(q)) {
Z_ADDREF_P(q);
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET(q);
} else {
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET_NULL();
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_NEXT();
p++;
i++;
}
} ZEND_HASH_FILL_END();
Z_ARRVAL_P(return_value)->nNumOfElements = arg_count;
} else {
RETURN_EMPTY_ARRAY();
1999-09-21 07:31:24 +00:00
}
}
2001-12-04 17:58:32 +00:00
/* }}} */
1999-09-21 07:31:24 +00:00
1999-09-20 16:56:09 +00:00
/* {{{ proto int strlen(string str)
Get string length
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
ZEND_FUNCTION(strlen)
1999-09-20 16:56:09 +00:00
{
zend_string *s;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(s)
ZEND_PARSE_PARAMETERS_END();
RETVAL_LONG(ZSTR_LEN(s));
1999-09-20 16:56:09 +00:00
}
/* }}} */
/* {{{ proto int strcmp(string str1, string str2)
Binary safe string comparison */
ZEND_FUNCTION(strcmp)
{
zend_string *s1, *s2;
2015-01-03 09:22:58 +00:00
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(s1)
Z_PARAM_STR(s2)
ZEND_PARSE_PARAMETERS_END();
RETURN_LONG(zend_binary_strcmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
1999-09-20 16:56:09 +00:00
}
/* }}} */
/* {{{ proto int strncmp(string str1, string str2, int len)
Binary safe string comparison */
ZEND_FUNCTION(strncmp)
{
zend_string *s1, *s2;
2014-08-25 17:24:55 +00:00
zend_long len;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_STR(s1)
Z_PARAM_STR(s2)
Z_PARAM_LONG(len)
ZEND_PARSE_PARAMETERS_END();
if (len < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
RETURN_THROWS();
}
RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
}
/* }}} */
1999-09-20 16:56:09 +00:00
/* {{{ proto int strcasecmp(string str1, string str2)
Binary safe case-insensitive string comparison */
ZEND_FUNCTION(strcasecmp)
{
zend_string *s1, *s2;
2015-01-03 09:22:58 +00:00
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(s1)
Z_PARAM_STR(s2)
ZEND_PARSE_PARAMETERS_END();
RETURN_LONG(zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
1999-09-20 16:56:09 +00:00
}
/* }}} */
/* {{{ proto int strncasecmp(string str1, string str2, int len)
Binary safe string comparison */
ZEND_FUNCTION(strncasecmp)
{
zend_string *s1, *s2;
2014-08-25 17:24:55 +00:00
zend_long len;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_STR(s1)
Z_PARAM_STR(s2)
Z_PARAM_LONG(len)
ZEND_PARSE_PARAMETERS_END();
if (len < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
RETURN_THROWS();
}
RETURN_LONG(zend_binary_strncasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
}
/* }}} */
2008-12-30 18:55:16 +00:00
/* {{{ proto int error_reporting([int new_error_level])
2001-12-04 17:58:32 +00:00
Return the current error_reporting level, and if an argument was passed - change to the new level */
1999-09-20 16:56:09 +00:00
ZEND_FUNCTION(error_reporting)
{
2016-06-28 08:37:51 +00:00
zval *err = NULL;
1999-09-20 16:56:09 +00:00
int old_error_reporting;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(err)
ZEND_PARSE_PARAMETERS_END();
1999-09-20 16:56:09 +00:00
old_error_reporting = EG(error_reporting);
if (ZEND_NUM_ARGS() != 0) {
zend_string *new_val = zval_try_get_string(err);
if (UNEXPECTED(!new_val)) {
2020-03-30 14:27:38 +00:00
RETURN_THROWS();
}
do {
2015-01-13 05:30:54 +00:00
zend_ini_entry *p = EG(error_reporting_ini_entry);
if (!p) {
2017-12-04 10:21:35 +00:00
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
if (zv) {
p = EG(error_reporting_ini_entry) = (zend_ini_entry*)Z_PTR_P(zv);
} else {
break;
}
}
2015-01-13 05:30:54 +00:00
if (!p->modified) {
if (!EG(modified_ini_directives)) {
ALLOC_HASHTABLE(EG(modified_ini_directives));
zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
}
if (EXPECTED(zend_hash_add_ptr(EG(modified_ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), p) != NULL)) {
2015-01-13 05:30:54 +00:00
p->orig_value = p->value;
p->orig_modifiable = p->modifiable;
p->modified = 1;
}
2015-01-13 08:32:36 +00:00
} else if (p->orig_value != p->value) {
zend_string_release_ex(p->value, 0);
}
p->value = new_val;
if (Z_TYPE_P(err) == IS_LONG) {
EG(error_reporting) = Z_LVAL_P(err);
} else {
EG(error_reporting) = atoi(ZSTR_VAL(p->value));
}
} while (0);
1999-09-20 16:56:09 +00:00
}
2000-06-30 11:45:32 +00:00
2014-08-25 17:24:55 +00:00
RETVAL_LONG(old_error_reporting);
1999-09-20 17:01:38 +00:00
}
2001-12-04 17:58:32 +00:00
/* }}} */
static int validate_constant_array(HashTable *ht) /* {{{ */
{
int ret = 1;
zval *val;
2017-10-05 22:34:50 +00:00
GC_PROTECT_RECURSION(ht);
ZEND_HASH_FOREACH_VAL_IND(ht, val) {
ZVAL_DEREF(val);
if (Z_REFCOUNTED_P(val)) {
if (Z_TYPE_P(val) == IS_ARRAY) {
if (Z_REFCOUNTED_P(val)) {
2017-10-05 22:34:50 +00:00
if (Z_IS_RECURSIVE_P(val)) {
zend_error(E_WARNING, "Constants cannot be recursive arrays");
ret = 0;
break;
} else if (!validate_constant_array(Z_ARRVAL_P(val))) {
ret = 0;
break;
}
}
} else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE) {
zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
ret = 0;
break;
2015-01-03 09:22:58 +00:00
}
}
} ZEND_HASH_FOREACH_END();
2017-10-05 22:34:50 +00:00
GC_UNPROTECT_RECURSION(ht);
return ret;
}
/* }}} */
static void copy_constant_array(zval *dst, zval *src) /* {{{ */
{
zend_string *key;
zend_ulong idx;
zval *new_val, *val;
array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src)));
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(src), idx, key, val) {
/* constant arrays can't contain references */
ZVAL_DEREF(val);
if (key) {
new_val = zend_hash_add_new(Z_ARRVAL_P(dst), key, val);
} else {
new_val = zend_hash_index_add_new(Z_ARRVAL_P(dst), idx, val);
2015-01-03 09:22:58 +00:00
}
if (Z_TYPE_P(val) == IS_ARRAY) {
if (Z_REFCOUNTED_P(val)) {
copy_constant_array(new_val, val);
}
2017-11-02 04:13:35 +00:00
} else {
Z_TRY_ADDREF_P(val);
}
} ZEND_HASH_FOREACH_END();
}
/* }}} */
2018-02-04 07:44:28 +00:00
/* {{{ proto bool define(string constant_name, mixed value[, bool case_insensitive])
2001-12-04 17:58:32 +00:00
Define a new constant */
ZEND_FUNCTION(define)
{
2014-04-21 21:41:09 +00:00
zend_string *name;
zval *val, val_free;
zend_bool non_cs = 0;
zend_constant c;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(name)
Z_PARAM_ZVAL(val)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(non_cs)
ZEND_PARSE_PARAMETERS_END();
if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
zend_error(E_WARNING, "Class constants cannot be defined or redefined");
RETURN_FALSE;
}
if (non_cs) {
zend_error(E_WARNING,
"define(): Declaration of case-insensitive constants is no longer supported");
RETURN_FALSE;
}
ZVAL_UNDEF(&val_free);
switch (Z_TYPE_P(val)) {
2014-08-25 17:24:55 +00:00
case IS_LONG:
case IS_DOUBLE:
case IS_STRING:
case IS_FALSE:
case IS_TRUE:
2000-01-04 13:22:58 +00:00
case IS_NULL:
case IS_RESOURCE:
break;
case IS_ARRAY:
if (Z_REFCOUNTED_P(val)) {
if (!validate_constant_array(Z_ARRVAL_P(val))) {
RETURN_FALSE;
} else {
copy_constant_array(&c.value, val);
goto register_constant;
}
}
break;
case IS_OBJECT:
if (Z_OBJ_HT_P(val)->cast_object(Z_OBJ_P(val), &val_free, IS_STRING) == SUCCESS) {
val = &val_free;
break;
}
/* no break */
default:
zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
zval_ptr_dtor(&val_free);
RETURN_FALSE;
}
2015-01-03 09:22:58 +00:00
2017-05-23 12:25:21 +00:00
ZVAL_COPY(&c.value, val);
zval_ptr_dtor(&val_free);
register_constant:
/* non persistent */
ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, PHP_USER_CONSTANT);
2014-08-25 17:24:55 +00:00
c.name = zend_string_copy(name);
2014-12-13 22:06:14 +00:00
if (zend_register_constant(&c) == SUCCESS) {
2002-05-13 08:41:55 +00:00
RETURN_TRUE;
} else {
2002-05-13 08:41:55 +00:00
RETURN_FALSE;
}
}
2001-12-04 17:58:32 +00:00
/* }}} */
2002-03-02 13:26:37 +00:00
/* {{{ proto bool defined(string constant_name)
Check whether a constant exists
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
ZEND_FUNCTION(defined)
{
2014-04-24 20:56:15 +00:00
zend_string *name;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(name)
ZEND_PARSE_PARAMETERS_END();
2015-01-03 09:22:58 +00:00
if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
2001-12-04 17:58:32 +00:00
/* }}} */
2004-03-14 22:40:25 +00:00
/* {{{ proto string get_class([object object])
2000-02-27 18:41:19 +00:00
Retrieves the class name */
ZEND_FUNCTION(get_class)
{
zval *obj = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o", &obj) == FAILURE) {
RETURN_THROWS();
}
if (!obj) {
zend_class_entry *scope = zend_get_executed_scope();
if (scope) {
RETURN_STR_COPY(scope->name);
2004-03-14 22:40:25 +00:00
} else {
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
RETURN_THROWS();
2004-03-14 22:40:25 +00:00
}
}
RETURN_STR_COPY(Z_OBJCE_P(obj)->name);
}
/* }}} */
/* {{{ proto string get_called_class()
Retrieves the "Late Static Binding" class name */
ZEND_FUNCTION(get_called_class)
{
zend_class_entry *called_scope;
ZEND_PARSE_PARAMETERS_NONE();
called_scope = zend_get_called_scope(execute_data);
if (!called_scope) {
zend_throw_error(NULL, "get_called_class() must be called from within a class");
RETURN_THROWS();
}
RETURN_STR_COPY(called_scope->name);
}
/* }}} */
2015-06-23 18:15:24 +00:00
/* {{{ proto mixed get_parent_class([mixed object])
Retrieves the parent class name for object or class or current scope or false if not in a scope. */
ZEND_FUNCTION(get_parent_class)
{
zval *arg;
zend_class_entry *ce = NULL;
2015-01-03 09:22:58 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
RETURN_THROWS();
}
if (!ZEND_NUM_ARGS()) {
ce = zend_get_executed_scope();
if (ce && ce->parent) {
RETURN_STR_COPY(ce->parent->name);
} else {
RETURN_FALSE;
}
}
if (Z_TYPE_P(arg) == IS_OBJECT) {
ce = Z_OBJ_P(arg)->ce;
} else if (Z_TYPE_P(arg) == IS_STRING) {
ce = zend_lookup_class(Z_STR_P(arg));
}
if (ce && ce->parent) {
RETURN_STR_COPY(ce->parent->name);
} else {
RETURN_FALSE;
}
}
/* }}} */
2014-09-20 07:16:09 +00:00
static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* {{{ */
{
zval *obj;
zend_string *class_name;
2003-03-05 11:14:44 +00:00
zend_class_entry *instance_ce;
zend_class_entry *ce;
zend_bool allow_string = only_subclass;
2003-03-05 11:14:44 +00:00
zend_bool retval;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_ZVAL(obj)
Z_PARAM_STR(class_name)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(allow_string)
ZEND_PARSE_PARAMETERS_END();
/*
2015-01-03 09:22:58 +00: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) {
2014-12-13 22:06:14 +00:00
instance_ce = zend_lookup_class(Z_STR_P(obj));
if (!instance_ce) {
RETURN_FALSE;
}
} else if (Z_TYPE_P(obj) == IS_OBJECT) {
instance_ce = Z_OBJCE_P(obj);
} else {
RETURN_FALSE;
}
2015-01-19 14:10:01 +00:00
if (!only_subclass && EXPECTED(zend_string_equals(instance_ce->name, class_name))) {
retval = 1;
2003-03-05 11:14:44 +00:00
} else {
ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
2015-01-19 14:10:01 +00:00
if (!ce) {
2003-03-05 11:14:44 +00:00
retval = 0;
2015-01-19 14:10:01 +00:00
} else {
if (only_subclass && instance_ce == ce) {
retval = 0;
} else {
retval = instanceof_function(instance_ce, ce);
}
}
1999-12-15 22:37:05 +00:00
}
2003-03-05 11:14:44 +00:00
RETURN_BOOL(retval);
}
2014-09-20 07:16:09 +00:00
/* }}} */
2002-02-01 22:55:02 +00:00
2015-06-23 18:15:24 +00:00
/* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string])
2003-06-09 00:15:11 +00:00
Returns true if the object has this class as one of its parents */
2002-02-01 22:55:02 +00:00
ZEND_FUNCTION(is_subclass_of)
{
is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
2015-06-23 18:15:24 +00:00
/* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string])
Returns true if the first argument is an object and is this class or has this class as one of its parents, */
2002-02-01 22:55:02 +00:00
ZEND_FUNCTION(is_a)
{
is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ add_class_vars */
static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int statics, zval *return_value)
{
zend_property_info *prop_info;
zval *prop, prop_copy;
zend_string *key;
2014-04-22 13:46:34 +00:00
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
Squashed commit of the following: commit 2d3cac9e005d6bef9aa73ab57cc674aa53125954 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 11:54:47 2018 +0300 Fixed static property access commit 31786ee27282f319f3ef2a07635b1f325cbd67c6 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 11:05:29 2018 +0300 Avoid duplicate checks commit 5ae502b979ea33d058d01a9421eec5afd0084e8d Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 10:39:17 2018 +0300 Optimization commit 82c17f0e8af02c9cf7d1bbdae4e3158330148203 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 09:26:50 2018 +0300 Removed unused zend_duplicate_property_info() commit ba53d1d0dd91d5530328a11cac93ff9e75c462b5 Merge: eacc11b8fd c4b14370cf Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 09:24:13 2018 +0300 Merge branch 'master' into shadow * master: 7.0.33 next Sync NEWS [ci skip] add NEWS for 76582 Enforce ordering of property compare in object comparisons Fixed wrong assertion Skip test on unsuitable env commit eacc11b8fdeb002ee6a149defd8b5a8c3412896a Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 13:12:39 2018 +0300 Fixed failure of ext/spl/tests/array_017.phpt commit 62d1871430a1b81c84b790460afff0682648689a Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 11:55:07 2018 +0300 Fixed issues commit 1d37e3a40e4d07c4b933ed6f9d2e649dd01180f0 Merge: d6c3f098b6 1e550e6f7e Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 10:21:20 2018 +0300 Merge branch 'master' into shadow * master: Update NEWS Fix for bug #76582 Fix ssl stream reneg limit test to print only after first renegotiation Make a copy unconditionally Fix memory leak in pcre cache Remove not needed checking for <errno.h> Remove HAVE_ASSERT_H Add test for bug #76850 Fixed bug #76850 Exit code mangled by set locale/preg_match Remove empty PHP tags from test Fix #75273: php_zlib_inflate_filter() may not update bytes_consumed Fix PCRE2 exclusion and remove dead libs in Makefile.gcov Report mem leaks to stderr if no Win debugger is present Use combined assignment contanation operator Fixed bug #76796 Support fixed address mmap without replacement commit d6c3f098b6015e76d042691de0af2e1426c66829 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Sep 7 13:56:30 2018 +0300 Get rid of ZEND_ACC_SHADOW
2018-09-11 08:56:45 +00:00
if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
!zend_check_protected(prop_info->ce, scope)) ||
((prop_info->flags & ZEND_ACC_PRIVATE) &&
prop_info->ce != scope)) {
continue;
}
prop = NULL;
2014-11-06 11:50:03 +00:00
if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
prop = &ce->default_static_members_table[prop_info->offset];
ZVAL_DEINDIRECT(prop);
2014-11-06 11:50:03 +00:00
} else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
}
if (!prop) {
continue;
}
if (Z_ISUNDEF_P(prop)) {
/* Return uninitialized typed properties as a null value */
ZVAL_NULL(&prop_copy);
} else {
/* copy: enforce read only access */
ZVAL_COPY_OR_DUP(&prop_copy, prop);
}
prop = &prop_copy;
/* this is necessary to make it able to work with default array
* properties, returned to user */
if (Z_OPT_TYPE_P(prop) == IS_CONSTANT_AST) {
if (UNEXPECTED(zval_update_constant_ex(prop, NULL) != SUCCESS)) {
return;
}
}
2014-06-02 20:36:31 +00:00
zend_hash_add_new(Z_ARRVAL_P(return_value), key, prop);
} ZEND_HASH_FOREACH_END();
}
/* }}} */
/* {{{ proto array get_class_vars(string class_name)
Returns an array of default properties of the class. */
ZEND_FUNCTION(get_class_vars)
{
zend_string *class_name;
zend_class_entry *ce, *scope;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
RETURN_THROWS();
}
2014-12-13 22:06:14 +00:00
ce = zend_lookup_class(class_name);
if (!ce) {
RETURN_FALSE;
} else {
array_init(return_value);
if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
}
}
scope = zend_get_executed_scope();
add_class_vars(scope, ce, 0, return_value);
add_class_vars(scope, ce, 1, return_value);
}
}
/* }}} */
/* {{{ proto array get_object_vars(object obj)
Returns an array of object properties */
ZEND_FUNCTION(get_object_vars)
{
zval *obj;
zval *value;
HashTable *properties;
zend_string *key;
zend_object *zobj;
zend_ulong num_key;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT(obj)
ZEND_PARSE_PARAMETERS_END();
zobj = Z_OBJ_P(obj);
properties = zobj->handlers->get_properties(zobj);
2006-02-07 00:33:13 +00:00
if (properties == NULL) {
RETURN_EMPTY_ARRAY();
2006-02-07 00:33:13 +00:00
}
2017-10-05 22:34:50 +00:00
if (!zobj->ce->default_properties_count && properties == zobj->properties && !GC_IS_RECURSIVE(properties)) {
2014-12-22 23:49:47 +00:00
/* fast copy */
if (EXPECTED(zobj->handlers == &std_object_handlers)) {
RETURN_ARR(zend_proptable_to_symtable(properties, 0));
}
RETURN_ARR(zend_proptable_to_symtable(properties, 1));
2014-12-22 23:49:47 +00:00
} else {
array_init_size(return_value, zend_hash_num_elements(properties));
ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, value) {
zend_bool is_dynamic = 1;
if (Z_TYPE_P(value) == IS_INDIRECT) {
value = Z_INDIRECT_P(value);
if (UNEXPECTED(Z_ISUNDEF_P(value))) {
continue;
}
is_dynamic = 0;
}
if (key && zend_check_property_access(zobj, key, is_dynamic) == FAILURE) {
continue;
}
if (Z_ISREF_P(value) && Z_REFCOUNT_P(value) == 1) {
value = Z_REFVAL_P(value);
}
Z_TRY_ADDREF_P(value);
if (UNEXPECTED(!key)) {
/* This case is only possible due to loopholes, e.g. ArrayObject */
zend_hash_index_add(Z_ARRVAL_P(return_value), num_key, value);
} else if (!is_dynamic && ZSTR_VAL(key)[0] == 0) {
const char *prop_name, *class_name;
size_t prop_len;
zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
/* We assume here that a mangled property name is never
* numeric. This is probably a safe assumption, but
* theoretically someone might write an extension with
* private, numeric properties. Well, too bad.
*/
zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value);
} else {
zend_symtable_add_new(Z_ARRVAL_P(return_value), key, value);
2004-10-04 08:59:29 +00:00
}
2014-12-22 23:49:47 +00:00
} ZEND_HASH_FOREACH_END();
}
}
/* }}} */
2019-05-14 12:27:10 +00:00
/* {{{ proto array get_mangled_object_vars(object obj)
Returns an array of mangled object properties. Does not respect property visibility. */
ZEND_FUNCTION(get_mangled_object_vars)
{
zval *obj;
HashTable *properties;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT(obj)
ZEND_PARSE_PARAMETERS_END();
2019-06-11 08:29:20 +00:00
properties = Z_OBJ_HT_P(obj)->get_properties(Z_OBJ_P(obj));
2019-05-14 12:27:10 +00:00
if (!properties) {
ZVAL_EMPTY_ARRAY(return_value);
return;
}
properties = zend_proptable_to_symtable(properties,
(Z_OBJCE_P(obj)->default_properties_count ||
Z_OBJ_P(obj)->handlers != &std_object_handlers ||
GC_IS_RECURSIVE(properties)));
RETURN_ARR(properties);
}
/* }}} */
static int same_name(zend_string *key, zend_string *name) /* {{{ */
2013-03-19 11:45:48 +00:00
{
zend_string *lcname;
2014-12-24 12:56:54 +00:00
int ret;
if (key == name) {
return 1;
}
if (ZSTR_LEN(key) != ZSTR_LEN(name)) {
return 0;
}
2015-01-03 09:22:58 +00:00
lcname = zend_string_tolower(name);
ret = memcmp(ZSTR_VAL(lcname), ZSTR_VAL(key), ZSTR_LEN(key)) == 0;
zend_string_release_ex(lcname, 0);
2013-03-19 11:45:48 +00:00
return ret;
}
2014-09-20 07:16:09 +00:00
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto array get_class_methods(mixed class)
Returns an array of method names for class or class instance. */
2000-03-23 17:47:28 +00:00
ZEND_FUNCTION(get_class_methods)
{
zval *klass;
zval method_name;
zend_class_entry *ce = NULL;
zend_class_entry *scope;
2003-09-18 16:20:42 +00:00
zend_function *mptr;
2000-03-23 17:47:28 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &klass) == FAILURE) {
RETURN_THROWS();
2000-03-23 17:47:28 +00:00
}
if (Z_TYPE_P(klass) == IS_OBJECT) {
ce = Z_OBJCE_P(klass);
} else if (Z_TYPE_P(klass) == IS_STRING) {
ce = zend_lookup_class(Z_STR_P(klass));
}
2000-03-23 17:47:28 +00:00
if (!ce) {
2000-03-23 18:31:18 +00:00
RETURN_NULL();
}
array_init(return_value);
scope = zend_get_executed_scope();
2003-09-18 16:20:42 +00:00
ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) {
2015-01-03 09:22:58 +00:00
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
|| (scope &&
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
zend_check_protected(mptr->common.scope, scope))
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
scope == mptr->common.scope)))
) {
ZVAL_STR_COPY(&method_name, mptr->common.function_name);
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
}
} ZEND_HASH_FOREACH_END();
2000-03-23 17:47:28 +00:00
}
/* }}} */
/* {{{ proto bool method_exists(object object, string method)
2000-02-27 18:41:19 +00:00
Checks if the class method exists */
ZEND_FUNCTION(method_exists)
{
2015-01-03 09:22:58 +00:00
zval *klass;
zend_string *method_name;
zend_string *lcname;
zend_class_entry *ce;
zend_function *func;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL(klass)
Z_PARAM_STR(method_name)
ZEND_PARSE_PARAMETERS_END();
if (Z_TYPE_P(klass) == IS_OBJECT) {
ce = Z_OBJCE_P(klass);
} else if (Z_TYPE_P(klass) == IS_STRING) {
2014-12-13 22:06:14 +00:00
if ((ce = zend_lookup_class(Z_STR_P(klass))) == NULL) {
2014-03-03 08:10:15 +00:00
RETURN_FALSE;
}
} else {
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(klass));
RETURN_THROWS();
}
lcname = zend_string_tolower(method_name);
func = zend_hash_find_ptr(&ce->function_table, lcname);
zend_string_release_ex(lcname, 0);
if (func) {
/* Exclude shadow properties when checking a method on a specific class. Include
* them when checking an object, as method_exists() generally ignores visibility.
* TODO: Should we use EG(scope) for the object case instead? */
RETURN_BOOL(Z_TYPE_P(klass) == IS_OBJECT
|| !(func->common.fn_flags & ZEND_ACC_PRIVATE) || func->common.scope == ce);
}
if (Z_TYPE_P(klass) == IS_OBJECT) {
zend_object *obj = Z_OBJ_P(klass);
func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
if (func != NULL) {
Squashed commit of the following: commit 2399fc84c541da9c2176c5b7f6dd039a3c84dc64 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:38:08 2015 +0300 Removed useless assignment commit 796b6338174348eee0d74a67706d77b7ce1a60c3 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:35:31 2015 +0300 Fixed execution with overriden zend_execute_ex() commit 4a9fb125aa999059f8bc42ebb6ee573c7866b35b Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 02:02:58 2015 +0300 Fixed executor without global registers commit d456c30e00589ccda35a4b57ae903ef2d3c07d95 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 01:30:35 2015 +0300 Restored original behavior for tests/classes/__call_004.phpt commit 479646d37fef050536f1afb12b082618f1f1a3d0 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:32:17 2015 +0300 Fixed test. We don't keep stack frame for fake function anymore. commit 9ae61e33e24b2c811d4ab1ca4ab22847c64a780e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:30:09 2015 +0300 Use ZEND_ACC_CALL_VIA_TRAMPOLINE instead of ZEND_ACC_CALL_VIA_HANDLER. Keep ZEND_ACC_CALL_VIA_HANDLER for compatibility. commit 0a8403a2a0c27aa3db271774f8559739a6b8400e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:05:43 2015 +0300 Rename PROXY_CALL into CALL_TRAMPLINE. Generalize API to allow reuse EG(trampline) for other purposes. commit 4ea0525c10554e36185a0b8b6303106813b6a1c2 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 23:22:25 2015 +0300 Reuse EG(proxy_call_op) for all proxy. Move proxy related functions from zend_objects_API to zend_object_handlers. commit 529bf737ca388ad56fb4ae20ccb81e6276f25ec0 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 21:42:23 2015 +0300 Accurate use of proxy_call commit 5d62837d5ba3855743fe1981786ebd65d9da0b63 Merge: 83e749f 690843f Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:40:00 2015 +0300 Merge branch 'master' into opcodefy-call * master: Fixed GOTO executor Fixed typo Changed ArrayIterator implementation using zend_hash_iterator_... API. Allowed modification of itterated ArrayObject using the same behavior as proposed in `Fix "foreach" behavior`. Removed "Array was modified outside object and internal position is no longer valid" hack. commit 83e749ff3b6623e39b236a72e9b907d5b788ae5e Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:39:10 2015 +0300 Improved ZEND_PROXY_CALL commit 0c829afc534e6d5ff27a0dea3a4815da303bd1ef Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 15:14:49 2015 +0300 Reverted white-space changes commit df65144488afa3e9020d75e1ada5529b138afc5a Merge: 5fd2f97 97756d9 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 14:37:07 2015 +0300 Merge branch 'opcodefy-call' of github.com:laruence/php-src into opcodefy-call * 'opcodefy-call' of github.com:laruence/php-src: Ready for PR Fixed static call Improve performance by using prealloated op_arrray Respect called_scope Support internal magical __call/__callStatic opcode-fy magical __callStatic Opcode-fy magical __call commit 97756d9190e07a072a7b48135304dc25a964845f Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:07:59 2015 +0800 Ready for PR commit 74f993084627061e783645a866390b68e2981698 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:03:00 2015 +0800 Fixed static call commit ec1d9eb592db0c3b7b0e3d21e7f445ed8bccfd4d Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 18:23:17 2015 +0800 Improve performance by using prealloated op_arrray commit df7fbbf949c99f2c5ae3da2a1199235651c7cc82 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 15:10:02 2015 +0800 Respect called_scope commit 769d1d59fb48b6f7f93d7412eefbf26135fa3e59 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 12:19:23 2015 +0800 Support internal magical __call/__callStatic commit a980fedd5b0e0683713dd4f6eaad62adf4b4732f Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 18:35:41 2015 +0800 opcode-fy magical __callStatic commit 73855f7d53baa2efc2b8a88314f51c784c81b59d Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 14:21:55 2015 +0800 Opcode-fy magical __call
2015-04-10 20:01:00 +00:00
if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
/* Returns true to the fake Closure's __invoke */
RETVAL_BOOL(func->common.scope == zend_ce_closure
&& zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
2015-01-03 09:22:58 +00:00
zend_string_release_ex(func->common.function_name, 0);
Squashed commit of the following: commit 2399fc84c541da9c2176c5b7f6dd039a3c84dc64 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:38:08 2015 +0300 Removed useless assignment commit 796b6338174348eee0d74a67706d77b7ce1a60c3 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:35:31 2015 +0300 Fixed execution with overriden zend_execute_ex() commit 4a9fb125aa999059f8bc42ebb6ee573c7866b35b Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 02:02:58 2015 +0300 Fixed executor without global registers commit d456c30e00589ccda35a4b57ae903ef2d3c07d95 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 01:30:35 2015 +0300 Restored original behavior for tests/classes/__call_004.phpt commit 479646d37fef050536f1afb12b082618f1f1a3d0 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:32:17 2015 +0300 Fixed test. We don't keep stack frame for fake function anymore. commit 9ae61e33e24b2c811d4ab1ca4ab22847c64a780e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:30:09 2015 +0300 Use ZEND_ACC_CALL_VIA_TRAMPOLINE instead of ZEND_ACC_CALL_VIA_HANDLER. Keep ZEND_ACC_CALL_VIA_HANDLER for compatibility. commit 0a8403a2a0c27aa3db271774f8559739a6b8400e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:05:43 2015 +0300 Rename PROXY_CALL into CALL_TRAMPLINE. Generalize API to allow reuse EG(trampline) for other purposes. commit 4ea0525c10554e36185a0b8b6303106813b6a1c2 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 23:22:25 2015 +0300 Reuse EG(proxy_call_op) for all proxy. Move proxy related functions from zend_objects_API to zend_object_handlers. commit 529bf737ca388ad56fb4ae20ccb81e6276f25ec0 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 21:42:23 2015 +0300 Accurate use of proxy_call commit 5d62837d5ba3855743fe1981786ebd65d9da0b63 Merge: 83e749f 690843f Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:40:00 2015 +0300 Merge branch 'master' into opcodefy-call * master: Fixed GOTO executor Fixed typo Changed ArrayIterator implementation using zend_hash_iterator_... API. Allowed modification of itterated ArrayObject using the same behavior as proposed in `Fix "foreach" behavior`. Removed "Array was modified outside object and internal position is no longer valid" hack. commit 83e749ff3b6623e39b236a72e9b907d5b788ae5e Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:39:10 2015 +0300 Improved ZEND_PROXY_CALL commit 0c829afc534e6d5ff27a0dea3a4815da303bd1ef Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 15:14:49 2015 +0300 Reverted white-space changes commit df65144488afa3e9020d75e1ada5529b138afc5a Merge: 5fd2f97 97756d9 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 14:37:07 2015 +0300 Merge branch 'opcodefy-call' of github.com:laruence/php-src into opcodefy-call * 'opcodefy-call' of github.com:laruence/php-src: Ready for PR Fixed static call Improve performance by using prealloated op_arrray Respect called_scope Support internal magical __call/__callStatic opcode-fy magical __callStatic Opcode-fy magical __call commit 97756d9190e07a072a7b48135304dc25a964845f Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:07:59 2015 +0800 Ready for PR commit 74f993084627061e783645a866390b68e2981698 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:03:00 2015 +0800 Fixed static call commit ec1d9eb592db0c3b7b0e3d21e7f445ed8bccfd4d Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 18:23:17 2015 +0800 Improve performance by using prealloated op_arrray commit df7fbbf949c99f2c5ae3da2a1199235651c7cc82 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 15:10:02 2015 +0800 Respect called_scope commit 769d1d59fb48b6f7f93d7412eefbf26135fa3e59 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 12:19:23 2015 +0800 Support internal magical __call/__callStatic commit a980fedd5b0e0683713dd4f6eaad62adf4b4732f Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 18:35:41 2015 +0800 opcode-fy magical __callStatic commit 73855f7d53baa2efc2b8a88314f51c784c81b59d Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 14:21:55 2015 +0800 Opcode-fy magical __call
2015-04-10 20:01:00 +00:00
zend_free_trampoline(func);
return;
}
RETURN_TRUE;
}
}
RETURN_FALSE;
}
/* }}} */
2005-04-08 13:33:15 +00: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)
{
zval *object;
zend_string *property;
zend_class_entry *ce;
2005-04-08 13:33:15 +00:00
zend_property_info *property_info;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &object, &property) == FAILURE) {
RETURN_THROWS();
2005-04-08 13:33:15 +00:00
}
if (Z_TYPE_P(object) == IS_STRING) {
2014-12-13 22:06:14 +00:00
ce = zend_lookup_class(Z_STR_P(object));
if (!ce) {
RETURN_FALSE;
2015-01-03 09:22:58 +00:00
}
} else if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
} else {
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(object));
RETURN_THROWS();
}
Squashed commit of the following: commit 2d3cac9e005d6bef9aa73ab57cc674aa53125954 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 11:54:47 2018 +0300 Fixed static property access commit 31786ee27282f319f3ef2a07635b1f325cbd67c6 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 11:05:29 2018 +0300 Avoid duplicate checks commit 5ae502b979ea33d058d01a9421eec5afd0084e8d Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 10:39:17 2018 +0300 Optimization commit 82c17f0e8af02c9cf7d1bbdae4e3158330148203 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 09:26:50 2018 +0300 Removed unused zend_duplicate_property_info() commit ba53d1d0dd91d5530328a11cac93ff9e75c462b5 Merge: eacc11b8fd c4b14370cf Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Sep 11 09:24:13 2018 +0300 Merge branch 'master' into shadow * master: 7.0.33 next Sync NEWS [ci skip] add NEWS for 76582 Enforce ordering of property compare in object comparisons Fixed wrong assertion Skip test on unsuitable env commit eacc11b8fdeb002ee6a149defd8b5a8c3412896a Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 13:12:39 2018 +0300 Fixed failure of ext/spl/tests/array_017.phpt commit 62d1871430a1b81c84b790460afff0682648689a Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 11:55:07 2018 +0300 Fixed issues commit 1d37e3a40e4d07c4b933ed6f9d2e649dd01180f0 Merge: d6c3f098b6 1e550e6f7e Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Sep 10 10:21:20 2018 +0300 Merge branch 'master' into shadow * master: Update NEWS Fix for bug #76582 Fix ssl stream reneg limit test to print only after first renegotiation Make a copy unconditionally Fix memory leak in pcre cache Remove not needed checking for <errno.h> Remove HAVE_ASSERT_H Add test for bug #76850 Fixed bug #76850 Exit code mangled by set locale/preg_match Remove empty PHP tags from test Fix #75273: php_zlib_inflate_filter() may not update bytes_consumed Fix PCRE2 exclusion and remove dead libs in Makefile.gcov Report mem leaks to stderr if no Win debugger is present Use combined assignment contanation operator Fixed bug #76796 Support fixed address mmap without replacement commit d6c3f098b6015e76d042691de0af2e1426c66829 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Sep 7 13:56:30 2018 +0300 Get rid of ZEND_ACC_SHADOW
2018-09-11 08:56:45 +00:00
property_info = zend_hash_find_ptr(&ce->properties_info, property);
if (property_info != NULL
&& (!(property_info->flags & ZEND_ACC_PRIVATE)
|| property_info->ce == ce)) {
RETURN_TRUE;
}
if (Z_TYPE_P(object) == IS_OBJECT &&
Z_OBJ_HANDLER_P(object, has_property)(Z_OBJ_P(object), property, 2, NULL)) {
RETURN_TRUE;
2005-04-08 13:33:15 +00:00
}
RETURN_FALSE;
2005-04-08 13:33:15 +00:00
}
/* }}} */
static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
{
zend_string *name;
zend_string *lcname;
zend_class_entry *ce;
zend_bool autoload = 1;
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(name)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(autoload)
ZEND_PARSE_PARAMETERS_END();
if (!autoload) {
if (ZSTR_VAL(name)[0] == '\\') {
/* Ignore leading "\" */
lcname = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
} else {
lcname = zend_string_tolower(name);
}
ce = zend_hash_find_ptr(EG(class_table), lcname);
zend_string_release_ex(lcname, 0);
} else {
ce = zend_lookup_class(name);
}
if (ce) {
RETURN_BOOL(((ce->ce_flags & flags) == flags) && !(ce->ce_flags & skip_flags));
} else {
RETURN_FALSE;
}
}
/* {{{ */
/* {{{ proto bool class_exists(string classname [, bool autoload])
Checks if the class exists */
ZEND_FUNCTION(class_exists)
{
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
}
/* }}} */
/* {{{ proto bool interface_exists(string classname [, bool autoload])
Checks if the class exists */
ZEND_FUNCTION(interface_exists)
{
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED|ZEND_ACC_INTERFACE, 0);
}
/* }}} */
/* {{{ proto bool trait_exists(string traitname [, bool autoload])
Checks if the trait exists */
ZEND_FUNCTION(trait_exists)
{
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT, 0);
}
/* }}} */
2015-01-03 09:22:58 +00:00
/* {{{ proto bool function_exists(string function_name)
Checks if the function exists */
ZEND_FUNCTION(function_exists)
{
zend_string *name;
2002-09-16 01:36:48 +00:00
zend_function *func;
zend_string *lcname;
2015-01-03 09:22:58 +00:00
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(name)
ZEND_PARSE_PARAMETERS_END();
1999-12-22 18:49:23 +00:00
if (ZSTR_VAL(name)[0] == '\\') {
/* Ignore leading "\" */
lcname = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
} else {
lcname = zend_string_tolower(name);
}
2015-01-03 09:22:58 +00:00
func = zend_hash_find_ptr(EG(function_table), lcname);
zend_string_release_ex(lcname, 0);
1999-12-22 18:49:23 +00:00
2002-09-16 01:36:48 +00: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.
*/
RETURN_BOOL(func && (func->type != ZEND_INTERNAL_FUNCTION ||
func->internal_function.handler != zif_display_disabled_function));
}
/* }}} */
/* {{{ proto bool class_alias(string user_class_name , string alias_name [, bool autoload])
Creates an alias for user defined class */
ZEND_FUNCTION(class_alias)
{
zend_string *class_name;
char *alias_name;
zend_class_entry *ce;
size_t alias_name_len;
zend_bool autoload = 1;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ss|b", &class_name, &alias_name, &alias_name_len, &autoload) == FAILURE) {
RETURN_THROWS();
}
ce = zend_lookup_class_ex(class_name, NULL, !autoload ? ZEND_FETCH_CLASS_NO_AUTOLOAD : 0);
2015-01-03 09:22:58 +00:00
if (ce) {
2015-01-03 09:22:58 +00:00
if (ce->type == ZEND_USER_CLASS) {
if (zend_register_class_alias_ex(alias_name, alias_name_len, ce, 0) == SUCCESS) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), 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", ZSTR_VAL(class_name));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto array get_included_files(void)
Returns an array with the file names that were include_once()'d */
ZEND_FUNCTION(get_included_files)
{
zend_string *entry;
ZEND_PARSE_PARAMETERS_NONE();
array_init(return_value);
2014-04-22 13:46:34 +00:00
ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), entry) {
if (entry) {
2014-08-25 17:24:55 +00:00
add_next_index_str(return_value, zend_string_copy(entry));
}
} ZEND_HASH_FOREACH_END();
}
/* }}} */
/* {{{ proto bool trigger_error(string message [, int error_type])
Generates a user-level error/warning/notice message */
2000-06-02 12:36:54 +00:00
ZEND_FUNCTION(trigger_error)
{
2014-08-25 17:24:55 +00:00
zend_long error_type = E_USER_NOTICE;
char *message;
size_t message_len;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &message, &message_len, &error_type) == FAILURE) {
RETURN_THROWS();
}
switch (error_type) {
case E_USER_ERROR:
case E_USER_WARNING:
case E_USER_NOTICE:
case E_USER_DEPRECATED:
break;
default:
zend_argument_value_error(2, "must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE,"
" or E_USER_DEPRECATED");
RETURN_THROWS();
break;
}
2008-07-01 07:23:00 +00:00
zend_error((int)error_type, "%s", message);
// TODO Change to void
RETURN_TRUE;
}
/* }}} */
2015-06-23 18:15:24 +00:00
/* {{{ proto string set_error_handler(callable error_handler [, int error_types])
2000-06-12 22:03:53 +00:00
Sets a user-defined error handler function. Returns the previously defined error handler, or false on error */
2000-06-02 12:36:54 +00:00
ZEND_FUNCTION(set_error_handler)
{
zval *error_handler;
2014-08-25 17:24:55 +00:00
zend_long error_type = E_ALL;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &error_handler, &error_type) == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
if (!zend_is_callable(error_handler, 0, NULL)) {
zend_string *error_handler_name = zend_get_callable_name(error_handler);
zend_argument_type_error(1, "must be a valid callback");
zend_string_release_ex(error_handler_name, 0);
RETURN_THROWS();
}
}
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
ZVAL_COPY(return_value, &EG(user_error_handler));
}
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
ZVAL_UNDEF(&EG(user_error_handler));
return;
}
ZVAL_COPY(&EG(user_error_handler), error_handler);
EG(user_error_handler_error_reporting) = (int)error_type;
}
2000-06-02 12:36:54 +00:00
/* }}} */
/* {{{ proto void restore_error_handler(void)
Restores the previously defined error handler function */
ZEND_FUNCTION(restore_error_handler)
{
ZEND_PARSE_PARAMETERS_NONE();
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
zval zeh;
2015-01-03 09:22:58 +00:00
ZVAL_COPY_VALUE(&zeh, &EG(user_error_handler));
ZVAL_UNDEF(&EG(user_error_handler));
zval_ptr_dtor(&zeh);
}
if (zend_stack_is_empty(&EG(user_error_handlers))) {
ZVAL_UNDEF(&EG(user_error_handler));
} else {
zval *tmp;
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));
tmp = zend_stack_top(&EG(user_error_handlers));
ZVAL_COPY_VALUE(&EG(user_error_handler), tmp);
zend_stack_del_top(&EG(user_error_handlers));
}
// TODO Change to void
RETURN_TRUE;
}
2002-07-05 02:34:54 +00:00
/* }}} */
2015-06-23 18:15:24 +00:00
/* {{{ proto mixed set_exception_handler(callable exception_handler)
Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
ZEND_FUNCTION(set_exception_handler)
{
zval *exception_handler;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &exception_handler) == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
if (!zend_is_callable(exception_handler, 0, NULL)) {
zend_string *exception_handler_name = zend_get_callable_name(exception_handler);
zend_argument_type_error(1, "must be a valid callback");
zend_string_release_ex(exception_handler_name, 0);
RETURN_THROWS();
}
}
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
ZVAL_COPY(return_value, &EG(user_exception_handler));
}
zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
ZVAL_UNDEF(&EG(user_exception_handler));
return;
}
ZVAL_COPY(&EG(user_exception_handler), exception_handler);
}
/* }}} */
/* {{{ proto void restore_exception_handler(void)
Restores the previously defined exception handler function */
ZEND_FUNCTION(restore_exception_handler)
{
ZEND_PARSE_PARAMETERS_NONE();
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
zval_ptr_dtor(&EG(user_exception_handler));
}
if (zend_stack_is_empty(&EG(user_exception_handlers))) {
ZVAL_UNDEF(&EG(user_exception_handler));
} else {
zval *tmp = zend_stack_top(&EG(user_exception_handlers));
ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
zend_stack_del_top(&EG(user_exception_handlers));
}
// TODO Change to void
RETURN_TRUE;
}
/* }}} */
static void copy_class_or_interface_name(zval *array, zend_string *key, zend_class_entry *ce) /* {{{ */
{
if ((ce->refcount == 1 && !(ce->ce_flags & ZEND_ACC_IMMUTABLE)) ||
same_name(key, ce->name)) {
key = ce->name;
2000-06-09 15:40:37 +00:00
}
add_next_index_str(array, zend_string_copy(key));
}
2014-09-20 07:16:09 +00:00
/* }}} */
static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
2010-05-06 15:18:20 +00:00
{
zend_string *key;
zend_class_entry *ce;
2010-05-06 15:18:20 +00:00
ZEND_PARSE_PARAMETERS_NONE();
2010-05-06 15:18:20 +00:00
array_init(return_value);
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) {
if (key
&& ZSTR_VAL(key)[0] != 0
&& (ce->ce_flags & flags)
&& !(ce->ce_flags & skip_flags)) {
copy_class_or_interface_name(return_value, key, ce);
}
} ZEND_HASH_FOREACH_END();
2010-05-06 15:18:20 +00:00
}
/* {{{ */
/* {{{ proto array get_declared_traits()
Returns an array of all declared traits. */
ZEND_FUNCTION(get_declared_traits)
{
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT, 0);
}
2010-05-06 15:18:20 +00:00
/* }}} */
2003-06-02 12:13:11 +00:00
/* {{{ proto array get_declared_classes()
Returns an array of all declared classes. */
ZEND_FUNCTION(get_declared_classes)
{
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
}
/* }}} */
/* {{{ proto array get_declared_interfaces()
Returns an array of all declared interfaces. */
ZEND_FUNCTION(get_declared_interfaces)
{
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE, 0);
}
2014-09-20 07:16:09 +00:00
/* }}} */
2001-12-04 17:58:32 +00:00
/* {{{ proto array get_defined_functions(void)
Returns an array of all defined functions */
ZEND_FUNCTION(get_defined_functions)
{
2014-09-28 19:30:49 +00:00
zval internal, user;
zend_string *key;
zend_function *func;
zend_bool exclude_disabled = 0;
char *disable_functions = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &exclude_disabled) == FAILURE) {
RETURN_THROWS();
}
array_init(&internal);
array_init(&user);
array_init(return_value);
if (exclude_disabled) {
disable_functions = INI_STR("disable_functions");
}
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), key, func) {
if (key && ZSTR_VAL(key)[0] != 0) {
if (func->type == ZEND_INTERNAL_FUNCTION) {
if (disable_functions != NULL) {
if (strstr(disable_functions, func->common.function_name->val) == NULL) {
add_next_index_str(&internal, zend_string_copy(key));
}
} else {
add_next_index_str(&internal, zend_string_copy(key));
}
} else if (func->type == ZEND_USER_FUNCTION) {
add_next_index_str(&user, zend_string_copy(key));
}
}
} ZEND_HASH_FOREACH_END();
2014-09-24 09:26:09 +00:00
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
}
/* }}} */
/* {{{ proto array get_defined_vars(void)
Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
ZEND_FUNCTION(get_defined_vars)
{
zend_array *symbol_table;
2019-10-31 09:20:41 +00:00
ZEND_PARSE_PARAMETERS_NONE();
if (zend_forbid_dynamic_call("get_defined_vars()") == FAILURE) {
return;
}
symbol_table = zend_rebuild_symbol_table();
if (UNEXPECTED(symbol_table == NULL)) {
RETURN_EMPTY_ARRAY();
}
2015-04-08 06:30:47 +00:00
RETURN_ARR(zend_array_dup(symbol_table));
}
/* }}} */
#if ZEND_DEBUG && defined(ZTS)
2002-09-18 14:08:07 +00:00
ZEND_FUNCTION(zend_thread_id)
{
2019-10-31 09:20:41 +00:00
ZEND_PARSE_PARAMETERS_NONE();
2014-08-25 17:24:55 +00:00
RETURN_LONG((zend_long)tsrm_thread_id());
2002-09-18 14:08:07 +00:00
}
#endif
2002-03-02 13:48:13 +00:00
/* {{{ proto string get_resource_type(resource res)
Get the resource type name for a given resource */
ZEND_FUNCTION(get_resource_type)
{
const char *resource_type;
zval *z_resource_type;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_resource_type) == FAILURE) {
RETURN_THROWS();
}
2014-12-13 22:06:14 +00:00
resource_type = zend_rsrc_list_get_rsrc_type(Z_RES_P(z_resource_type));
if (resource_type) {
RETURN_STRING(resource_type);
} else {
RETURN_STRING("Unknown");
}
}
2002-03-02 13:48:13 +00:00
/* }}} */
2001-05-21 15:47:52 +00:00
/* {{{ proto array get_resources([string resouce_type])
Get an array with all active resources */
ZEND_FUNCTION(get_resources)
{
zend_string *type = NULL;
zend_string *key;
2014-08-25 17:24:55 +00:00
zend_ulong index;
zval *val;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &type) == FAILURE) {
RETURN_THROWS();
}
if (!type) {
array_init(return_value);
ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
if (!key) {
Z_ADDREF_P(val);
zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
}
} ZEND_HASH_FOREACH_END();
} else if (zend_string_equals_literal(type, "Unknown")) {
array_init(return_value);
ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
if (!key && Z_RES_TYPE_P(val) <= 0) {
Z_ADDREF_P(val);
zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
}
} ZEND_HASH_FOREACH_END();
} else {
int id = zend_fetch_list_dtor_id(ZSTR_VAL(type));
if (id <= 0) {
zend_error(E_WARNING, "get_resources(): Unknown resource type '%s'", ZSTR_VAL(type));
RETURN_FALSE;
}
array_init(return_value);
ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
if (!key && Z_RES_TYPE_P(val) == id) {
Z_ADDREF_P(val);
zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
}
} ZEND_HASH_FOREACH_END();
}
}
/* }}} */
2001-05-21 15:47:52 +00:00
static void add_zendext_info(zend_extension *ext, void *arg) /* {{{ */
{
zval *name_array = (zval *)arg;
2014-04-15 11:40:40 +00:00
add_next_index_string(name_array, ext->name);
}
2014-09-20 07:16:09 +00:00
/* }}} */
/* {{{ proto array get_loaded_extensions([bool zend_extensions])
2001-05-21 15:47:52 +00:00
Return an array containing names of loaded extensions */
ZEND_FUNCTION(get_loaded_extensions)
{
2007-08-02 20:32:44 +00:00
zend_bool zendext = 0;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &zendext) == FAILURE) {
RETURN_THROWS();
2001-05-21 15:47:52 +00:00
}
array_init(return_value);
if (zendext) {
zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) add_zendext_info, return_value);
} else {
zend_module_entry *module;
ZEND_HASH_FOREACH_PTR(&module_registry, module) {
add_next_index_string(return_value, module->name);
} ZEND_HASH_FOREACH_END();
}
2001-05-21 15:47:52 +00:00
}
/* }}} */
/* {{{ proto array get_defined_constants([bool categorize])
2001-05-21 15:47:52 +00:00
Return an array containing the names and values of all defined constants */
ZEND_FUNCTION(get_defined_constants)
{
zend_bool categorize = 0;
2015-01-03 09:22:58 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &categorize) == FAILURE) {
RETURN_THROWS();
2001-05-21 15:47:52 +00:00
}
array_init(return_value);
if (categorize) {
zend_constant *val;
int module_number;
2014-06-02 22:43:31 +00:00
zval *modules, const_val;
2008-01-24 18:07:45 +00:00
char **module_names;
zend_module_entry *module;
int i = 1;
modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval));
module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
module_names[0] = "internal";
ZEND_HASH_FOREACH_PTR(&module_registry, module) {
module_names[module->module_number] = (char *)module->name;
i++;
} ZEND_HASH_FOREACH_END();
module_names[i] = "user";
ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) {
if (!val->name) {
/* skip special constants */
continue;
}
if (ZEND_CONSTANT_MODULE_NUMBER(val) == PHP_USER_CONSTANT) {
module_number = i;
} else if (ZEND_CONSTANT_MODULE_NUMBER(val) > i) {
/* should not happen */
continue;
} else {
module_number = ZEND_CONSTANT_MODULE_NUMBER(val);
}
if (Z_TYPE(modules[module_number]) == IS_UNDEF) {
array_init(&modules[module_number]);
add_assoc_zval(return_value, module_names[module_number], &modules[module_number]);
}
ZVAL_COPY_OR_DUP(&const_val, &val->value);
2014-06-02 22:43:31 +00:00
zend_hash_add_new(Z_ARRVAL(modules[module_number]), val->name, &const_val);
} ZEND_HASH_FOREACH_END();
efree(module_names);
efree(modules);
} else {
zend_constant *constant;
zval const_val;
ZEND_HASH_FOREACH_PTR(EG(zend_constants), constant) {
if (!constant->name) {
/* skip special constants */
continue;
}
ZVAL_COPY_OR_DUP(&const_val, &constant->value);
zend_hash_add_new(Z_ARRVAL_P(return_value), constant->name, &const_val);
} ZEND_HASH_FOREACH_END();
}
2001-05-21 15:47:52 +00:00
}
2002-07-05 02:34:54 +00:00
/* }}} */
2001-05-21 15:47:52 +00:00
2014-12-13 22:06:14 +00:00
static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /* {{{ */
2004-02-25 21:06:59 +00:00
{
uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
if (num_args) {
2014-09-15 10:08:42 +00:00
uint32_t i = 0;
zval *p = ZEND_CALL_ARG(call, 1);
array_init_size(arg_array, num_args);
2018-03-22 21:13:45 +00:00
zend_hash_real_init_packed(Z_ARRVAL_P(arg_array));
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) {
if (call->func->type == ZEND_USER_FUNCTION) {
uint32_t first_extra_arg = MIN(num_args, call->func->op_array.num_args);
2015-01-03 09:22:58 +00:00
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
/* In case of attached symbol_table, values on stack may be invalid
* and we have to access them through symbol_table
* See: https://bugs.php.net/bug.php?id=73156
*/
zend_string *arg_name;
zval *arg;
while (i < first_extra_arg) {
arg_name = call->func->op_array.vars[i];
2017-12-04 10:21:35 +00:00
arg = zend_hash_find_ex_ind(call->symbol_table, arg_name, 1);
if (arg) {
if (Z_OPT_REFCOUNTED_P(arg)) {
Z_ADDREF_P(arg);
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET(arg);
} else {
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET_NULL();
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_NEXT();
i++;
}
} else {
while (i < first_extra_arg) {
if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) {
if (Z_OPT_REFCOUNTED_P(p)) {
Z_ADDREF_P(p);
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET(p);
} else {
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET_NULL();
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_NEXT();
p++;
i++;
}
}
p = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
}
while (i < num_args) {
if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) {
if (Z_OPT_REFCOUNTED_P(p)) {
Z_ADDREF_P(p);
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET(p);
} else {
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_SET_NULL();
}
2019-05-28 10:35:00 +00:00
ZEND_HASH_FILL_NEXT();
p++;
i++;
}
} ZEND_HASH_FILL_END();
Z_ARRVAL_P(arg_array)->nNumOfElements = num_args;
} else {
ZVAL_EMPTY_ARRAY(arg_array);
}
}
2014-09-20 07:16:09 +00:00
/* }}} */
2014-12-13 22:06:14 +00:00
void debug_print_backtrace_args(zval *arg_array) /* {{{ */
2002-12-01 19:47:02 +00:00
{
zval *tmp;
2002-12-01 19:47:02 +00:00
int i = 0;
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arg_array), tmp) {
2002-12-01 19:47:02 +00:00
if (i++) {
ZEND_PUTS(", ");
}
2014-12-13 22:06:14 +00:00
zend_print_flat_zval_r(tmp);
} ZEND_HASH_FOREACH_END();
2002-12-01 19:47:02 +00:00
}
2014-09-20 07:16:09 +00:00
/* }}} */
2002-12-01 19:47:02 +00:00
static inline zend_bool skip_internal_handler(zend_execute_data *skip) /* {{{ */
{
return !(skip->func && ZEND_USER_CODE(skip->func->common.type))
&& skip->prev_execute_data
&& skip->prev_execute_data->func
&& ZEND_USER_CODE(skip->prev_execute_data->func->common.type)
&& skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL
&& skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL
&& skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL
&& skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME
&& skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL;
}
/* {{{ */
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
2002-12-01 19:47:02 +00:00
ZEND_FUNCTION(debug_print_backtrace)
{
2014-07-07 11:50:44 +00:00
zend_execute_data *call, *ptr, *skip;
zend_object *object;
int lineno, frameno = 0;
zend_function *func;
const char *function_name;
const char *filename;
zend_string *class_name = NULL;
2002-12-01 19:47:02 +00:00
char *call_type;
const char *include_filename = NULL;
zval arg_array;
int indent = 0;
2014-08-25 17:24:55 +00:00
zend_long options = 0;
zend_long limit = 0;
2002-12-01 19:47:02 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
RETURN_THROWS();
2002-12-01 19:47:02 +00:00
}
ZVAL_UNDEF(&arg_array);
ptr = EX(prev_execute_data);
2002-12-01 19:47:02 +00:00
/* skip debug_backtrace() */
2014-07-07 11:50:44 +00:00
call = ptr;
2002-12-01 19:47:02 +00:00
ptr = ptr->prev_execute_data;
while (ptr && (limit == 0 || frameno < limit)) {
frameno++;
class_name = NULL;
2015-01-03 09:22:58 +00:00
call_type = NULL;
ZVAL_UNDEF(&arg_array);
2015-03-06 23:28:12 +00:00
ptr = zend_generator_check_placeholder_frame(ptr);
skip = ptr;
/* skip internal handler */
if (skip_internal_handler(skip)) {
skip = skip->prev_execute_data;
}
if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
filename = ZSTR_VAL(skip->func->op_array.filename);
if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
if (EG(opline_before_exception)) {
lineno = EG(opline_before_exception)->lineno;
} else {
lineno = skip->func->op_array.line_end;
}
} else {
lineno = skip->opline->lineno;
}
2002-12-01 19:47:02 +00:00
} else {
filename = NULL;
lineno = 0;
2002-12-01 19:47:02 +00:00
}
/* $this may be passed into regular internal functions */
object = (Z_TYPE(call->This) == IS_OBJECT) ? Z_OBJ(call->This) : NULL;
2014-07-07 11:50:44 +00:00
if (call->func) {
2017-01-23 05:33:58 +00:00
func = call->func;
if (func->common.function_name) {
function_name = ZSTR_VAL(func->common.function_name);
} else {
function_name = NULL;
}
} else {
2014-07-07 11:50:44 +00:00
func = NULL;
function_name = NULL;
}
2002-12-01 19:47:02 +00:00
if (function_name) {
if (object) {
if (func->common.scope) {
class_name = func->common.scope->name;
} else if (object->handlers->get_class_name == zend_std_get_class_name) {
class_name = object->ce->name;
} else {
class_name = object->handlers->get_class_name(object);
}
2002-12-01 19:47:02 +00:00
call_type = "->";
} else if (func->common.scope) {
class_name = func->common.scope->name;
2002-12-01 19:47:02 +00:00
call_type = "::";
} else {
class_name = NULL;
call_type = NULL;
}
if (func->type != ZEND_EVAL_CODE) {
if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) {
2014-12-13 22:06:14 +00:00
debug_backtrace_get_args(call, &arg_array);
2002-12-01 19:47:02 +00:00
}
}
2002-12-01 19:47:02 +00: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;
2014-07-07 11:50:44 +00:00
if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
/* can happen when calling eval from a custom sapi */
function_name = "unknown";
build_filename_arg = 0;
} else
switch (ptr->opline->extended_value) {
2002-12-01 19:47:02 +00: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:
2015-01-03 09:22:58 +00:00
/* this can actually happen if you use debug_backtrace() in your error_handler and
2002-12-01 19:47:02 +00:00
* you're in the top-scope */
2015-01-03 09:22:58 +00:00
function_name = "unknown";
2002-12-01 19:47:02 +00:00
build_filename_arg = 0;
break;
}
if (build_filename_arg && include_filename) {
array_init(&arg_array);
2014-04-15 11:40:40 +00:00
add_next_index_string(&arg_array, (char*)include_filename);
2002-12-01 19:47:02 +00:00
}
call_type = NULL;
2002-12-01 19:47:02 +00:00
}
zend_printf("#%-2d ", indent);
if (class_name) {
ZEND_PUTS(ZSTR_VAL(class_name));
2002-12-01 19:47:02 +00:00
ZEND_PUTS(call_type);
if (object
&& !func->common.scope
&& object->handlers->get_class_name != zend_std_get_class_name) {
zend_string_release_ex(class_name, 0);
}
2002-12-01 19:47:02 +00:00
}
2011-08-07 06:19:43 +00:00
zend_printf("%s(", function_name);
if (Z_TYPE(arg_array) != IS_UNDEF) {
2014-12-13 22:06:14 +00:00
debug_print_backtrace_args(&arg_array);
2003-01-08 16:41:47 +00:00
zval_ptr_dtor(&arg_array);
}
if (filename) {
zend_printf(") called at [%s:%d]\n", filename, lineno);
} else {
2014-07-07 11:50:44 +00:00
zend_execute_data *prev_call = skip;
zend_execute_data *prev = skip->prev_execute_data;
while (prev) {
2014-07-07 11:50:44 +00:00
if (prev_call &&
prev_call->func &&
2014-07-07 11:50:44 +00:00
!ZEND_USER_CODE(prev_call->func->common.type)) {
prev = NULL;
break;
2015-01-03 09:22:58 +00:00
}
if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
zend_printf(") called at [%s:%d]\n", ZSTR_VAL(prev->func->op_array.filename), prev->opline->lineno);
break;
}
2014-07-07 11:50:44 +00:00
prev_call = prev;
prev = prev->prev_execute_data;
}
if (!prev) {
ZEND_PUTS(")\n");
}
}
2004-09-09 16:47:22 +00:00
include_filename = filename;
2014-07-07 11:50:44 +00:00
call = skip;
ptr = skip->prev_execute_data;
2002-12-01 19:47:02 +00:00
++indent;
}
}
/* }}} */
2014-12-13 22:06:14 +00:00
ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit) /* {{{ */
{
zend_execute_data *ptr, *skip, *call = NULL;
2014-07-07 11:50:44 +00:00
zend_object *object;
int lineno, frameno = 0;
zend_function *func;
zend_string *function_name;
zend_string *filename;
zend_string *include_filename = NULL;
zval stack_frame, tmp;
array_init(return_value);
if (!(ptr = EG(current_execute_data))) {
return;
}
2014-07-07 11:50:44 +00:00
if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type)) {
call = ptr;
ptr = ptr->prev_execute_data;
}
if (ptr) {
if (skip_last) {
/* skip debug_backtrace() */
2014-07-07 11:50:44 +00:00
call = ptr;
ptr = ptr->prev_execute_data;
} else {
/* skip "new Exception()" */
2014-07-07 11:50:44 +00:00
if (ptr->func && ZEND_USER_CODE(ptr->func->common.type) && (ptr->opline->opcode == ZEND_NEW)) {
call = ptr;
ptr = ptr->prev_execute_data;
}
}
if (!call) {
call = ptr;
ptr = ptr->prev_execute_data;
}
}
while (ptr && (limit == 0 || frameno < limit)) {
frameno++;
array_init(&stack_frame);
2015-03-06 23:28:12 +00:00
ptr = zend_generator_check_placeholder_frame(ptr);
skip = ptr;
/* skip internal handler */
if (skip_internal_handler(skip)) {
skip = skip->prev_execute_data;
}
if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
filename = skip->func->op_array.filename;
if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
if (EG(opline_before_exception)) {
lineno = EG(opline_before_exception)->lineno;
} else {
lineno = skip->func->op_array.line_end;
}
} else {
lineno = skip->opline->lineno;
}
ZVAL_STR_COPY(&tmp, filename);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FILE), &tmp);
ZVAL_LONG(&tmp, lineno);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_LINE), &tmp);
/* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function
2015-01-03 09:22:58 +00:00
* 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 */
} else {
2014-07-07 11:50:44 +00:00
zend_execute_data *prev_call = skip;
zend_execute_data *prev = skip->prev_execute_data;
while (prev) {
2014-07-07 11:50:44 +00:00
if (prev_call &&
prev_call->func &&
2014-07-07 11:50:44 +00:00
!ZEND_USER_CODE(prev_call->func->common.type) &&
Squashed commit of the following: commit 2399fc84c541da9c2176c5b7f6dd039a3c84dc64 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:38:08 2015 +0300 Removed useless assignment commit 796b6338174348eee0d74a67706d77b7ce1a60c3 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 12:35:31 2015 +0300 Fixed execution with overriden zend_execute_ex() commit 4a9fb125aa999059f8bc42ebb6ee573c7866b35b Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 02:02:58 2015 +0300 Fixed executor without global registers commit d456c30e00589ccda35a4b57ae903ef2d3c07d95 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 01:30:35 2015 +0300 Restored original behavior for tests/classes/__call_004.phpt commit 479646d37fef050536f1afb12b082618f1f1a3d0 Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:32:17 2015 +0300 Fixed test. We don't keep stack frame for fake function anymore. commit 9ae61e33e24b2c811d4ab1ca4ab22847c64a780e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:30:09 2015 +0300 Use ZEND_ACC_CALL_VIA_TRAMPOLINE instead of ZEND_ACC_CALL_VIA_HANDLER. Keep ZEND_ACC_CALL_VIA_HANDLER for compatibility. commit 0a8403a2a0c27aa3db271774f8559739a6b8400e Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Apr 10 00:05:43 2015 +0300 Rename PROXY_CALL into CALL_TRAMPLINE. Generalize API to allow reuse EG(trampline) for other purposes. commit 4ea0525c10554e36185a0b8b6303106813b6a1c2 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 23:22:25 2015 +0300 Reuse EG(proxy_call_op) for all proxy. Move proxy related functions from zend_objects_API to zend_object_handlers. commit 529bf737ca388ad56fb4ae20ccb81e6276f25ec0 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 21:42:23 2015 +0300 Accurate use of proxy_call commit 5d62837d5ba3855743fe1981786ebd65d9da0b63 Merge: 83e749f 690843f Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:40:00 2015 +0300 Merge branch 'master' into opcodefy-call * master: Fixed GOTO executor Fixed typo Changed ArrayIterator implementation using zend_hash_iterator_... API. Allowed modification of itterated ArrayObject using the same behavior as proposed in `Fix "foreach" behavior`. Removed "Array was modified outside object and internal position is no longer valid" hack. commit 83e749ff3b6623e39b236a72e9b907d5b788ae5e Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 19:39:10 2015 +0300 Improved ZEND_PROXY_CALL commit 0c829afc534e6d5ff27a0dea3a4815da303bd1ef Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 15:14:49 2015 +0300 Reverted white-space changes commit df65144488afa3e9020d75e1ada5529b138afc5a Merge: 5fd2f97 97756d9 Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Apr 9 14:37:07 2015 +0300 Merge branch 'opcodefy-call' of github.com:laruence/php-src into opcodefy-call * 'opcodefy-call' of github.com:laruence/php-src: Ready for PR Fixed static call Improve performance by using prealloated op_arrray Respect called_scope Support internal magical __call/__callStatic opcode-fy magical __callStatic Opcode-fy magical __call commit 97756d9190e07a072a7b48135304dc25a964845f Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:07:59 2015 +0800 Ready for PR commit 74f993084627061e783645a866390b68e2981698 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 19:03:00 2015 +0800 Fixed static call commit ec1d9eb592db0c3b7b0e3d21e7f445ed8bccfd4d Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 18:23:17 2015 +0800 Improve performance by using prealloated op_arrray commit df7fbbf949c99f2c5ae3da2a1199235651c7cc82 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 15:10:02 2015 +0800 Respect called_scope commit 769d1d59fb48b6f7f93d7412eefbf26135fa3e59 Author: Xinchen Hui <laruence@gmail.com> Date: Thu Apr 9 12:19:23 2015 +0800 Support internal magical __call/__callStatic commit a980fedd5b0e0683713dd4f6eaad62adf4b4732f Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 18:35:41 2015 +0800 opcode-fy magical __callStatic commit 73855f7d53baa2efc2b8a88314f51c784c81b59d Author: Xinchen Hui <laruence@gmail.com> Date: Wed Apr 8 14:21:55 2015 +0800 Opcode-fy magical __call
2015-04-10 20:01:00 +00:00
!(prev_call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
break;
2015-01-03 09:22:58 +00:00
}
if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
ZVAL_STR_COPY(&tmp, prev->func->op_array.filename);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FILE), &tmp);
ZVAL_LONG(&tmp, prev->opline->lineno);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_LINE), &tmp);
break;
}
2014-07-07 11:50:44 +00:00
prev_call = prev;
prev = prev->prev_execute_data;
}
filename = NULL;
}
/* $this may be passed into regular internal functions */
object = (call && (Z_TYPE(call->This) == IS_OBJECT)) ? Z_OBJ(call->This) : NULL;
2014-07-07 11:50:44 +00:00
if (call && call->func) {
func = call->func;
function_name = func->common.function_name;
} else {
2014-07-07 11:50:44 +00:00
func = NULL;
function_name = NULL;
}
if (function_name) {
ZVAL_STR_COPY(&tmp, function_name);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp);
if (object) {
if (func->common.scope) {
ZVAL_STR_COPY(&tmp, func->common.scope->name);
} else if (object->handlers->get_class_name == zend_std_get_class_name) {
ZVAL_STR_COPY(&tmp, object->ce->name);
} else {
ZVAL_STR(&tmp, object->handlers->get_class_name(object));
}
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_CLASS), &tmp);
if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
ZVAL_OBJ(&tmp, object);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_OBJECT), &tmp);
Z_ADDREF(tmp);
}
ZVAL_INTERNED_STR(&tmp, ZSTR_KNOWN(ZEND_STR_OBJECT_OPERATOR));
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_TYPE), &tmp);
} else if (func->common.scope) {
ZVAL_STR_COPY(&tmp, func->common.scope->name);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_CLASS), &tmp);
ZVAL_INTERNED_STR(&tmp, ZSTR_KNOWN(ZEND_STR_PAAMAYIM_NEKUDOTAYIM));
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_TYPE), &tmp);
}
2015-01-03 09:22:58 +00:00
if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 &&
func->type != ZEND_EVAL_CODE) {
2014-07-07 11:50:44 +00:00
debug_backtrace_get_args(call, &tmp);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_ARGS), &tmp);
}
} 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;
zend_string *pseudo_function_name;
2014-07-07 11:50:44 +00:00
if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
/* can happen when calling eval from a custom sapi */
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
build_filename_arg = 0;
} else
switch (ptr->opline->extended_value) {
2002-08-24 20:52:52 +00:00
case ZEND_EVAL:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_EVAL);
build_filename_arg = 0;
2002-08-24 20:52:52 +00:00
break;
case ZEND_INCLUDE:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_INCLUDE);
2002-08-24 20:52:52 +00:00
break;
case ZEND_REQUIRE:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_REQUIRE);
2002-08-24 20:52:52 +00:00
break;
case ZEND_INCLUDE_ONCE:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_INCLUDE_ONCE);
2002-08-24 20:52:52 +00:00
break;
case ZEND_REQUIRE_ONCE:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_REQUIRE_ONCE);
2002-08-24 20:52:52 +00:00
break;
default:
2015-01-03 09:22:58 +00:00
/* this can actually happen if you use debug_backtrace() in your error_handler and
* you're in the top-scope */
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
build_filename_arg = 0;
2002-08-24 20:52:52 +00:00
break;
2002-08-24 09:05:44 +00:00
}
if (build_filename_arg && include_filename) {
zval arg_array;
array_init(&arg_array);
2013-07-23 23:55:43 +00:00
/* include_filename always points to the last filename of the last last called-function.
if we have called include in the frame above - this is the file we have included.
2002-08-24 09:05:44 +00:00
*/
ZVAL_STR_COPY(&tmp, include_filename);
zend_hash_next_index_insert_new(Z_ARRVAL(arg_array), &tmp);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_ARGS), &arg_array);
}
ZVAL_INTERNED_STR(&tmp, pseudo_function_name);
zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp);
}
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &stack_frame);
2015-01-03 09:22:58 +00:00
include_filename = filename;
2014-07-07 11:50:44 +00:00
call = skip;
ptr = skip->prev_execute_data;
}
}
2002-07-05 02:34:54 +00:00
/* }}} */
/* {{{ proto array debug_backtrace([int options[, int limit]])
Return backtrace as array */
ZEND_FUNCTION(debug_backtrace)
{
2014-08-25 17:24:55 +00:00
zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
zend_long limit = 0;
2015-01-03 09:22:58 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
RETURN_THROWS();
}
2014-12-13 22:06:14 +00:00
zend_fetch_debug_backtrace(return_value, 1, options, limit);
}
/* }}} */
2001-05-21 15:47:52 +00:00
/* {{{ proto bool extension_loaded(string extension_name)
Returns true if the named extension is loaded */
ZEND_FUNCTION(extension_loaded)
{
zend_string *extension_name;
zend_string *lcname;
2001-05-21 15:47:52 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
RETURN_THROWS();
2001-05-21 15:47:52 +00:00
}
lcname = zend_string_tolower(extension_name);
if (zend_hash_exists(&module_registry, lcname)) {
2004-03-29 18:48:59 +00:00
RETVAL_TRUE;
2001-05-21 15:47:52 +00:00
} else {
2004-03-29 18:48:59 +00:00
RETVAL_FALSE;
2001-05-21 15:47:52 +00:00
}
zend_string_release_ex(lcname, 0);
2001-05-21 15:47:52 +00: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)
{
zend_string *extension_name;
zend_string *lcname;
int array;
2001-05-21 15:47:52 +00:00
zend_module_entry *module;
zend_function *zif;
2015-01-03 09:22:58 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
RETURN_THROWS();
2001-05-21 15:47:52 +00:00
}
if (strncasecmp(ZSTR_VAL(extension_name), "zend", sizeof("zend"))) {
lcname = zend_string_tolower(extension_name);
2015-07-02 04:31:26 +00:00
module = zend_hash_find_ptr(&module_registry, lcname);
zend_string_release_ex(lcname, 0);
} else {
2015-07-02 04:31:26 +00:00
module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core") - 1);
}
2015-07-02 04:31:26 +00:00
if (!module) {
RETURN_FALSE;
}
if (module->functions) {
/* avoid BC break, if functions list is empty, will return an empty array */
array_init(return_value);
array = 1;
} else {
array = 0;
}
ZEND_HASH_FOREACH_PTR(CG(function_table), zif) {
2014-03-03 09:06:04 +00:00
if (zif->common.type == ZEND_INTERNAL_FUNCTION
&& zif->internal_function.module == module) {
if (!array) {
array_init(return_value);
array = 1;
}
2014-08-25 17:24:55 +00:00
add_next_index_str(return_value, zend_string_copy(zif->common.function_name));
}
} ZEND_HASH_FOREACH_END();
2001-05-21 15:47:52 +00:00
if (!array) {
RETURN_FALSE;
2001-05-21 15:47:52 +00:00
}
}
/* }}} */