1999-09-20 20:24:39 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 13:26:39 +08:00
|
|
|
| Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-09-20 20:24:39 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 13:26:39 +08:00
|
|
|
| This source file is subject to version 0.92 of the Zend license, |
|
1999-09-20 20:24:39 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-03-06 13:26:39 +08:00
|
|
|
| http://www.zend.com/license/0_92.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> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_builtin_functions.h"
|
1999-09-21 05:28:37 +08:00
|
|
|
#include "zend_constants.h"
|
1999-09-20 20:24:39 +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);
|
1999-09-21 00:56:09 +08:00
|
|
|
static ZEND_FUNCTION(strlen);
|
|
|
|
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);
|
|
|
|
static ZEND_FUNCTION(get_parent_class);
|
|
|
|
static ZEND_FUNCTION(method_exists);
|
1999-12-15 05:15:24 +08:00
|
|
|
static ZEND_FUNCTION(class_exists);
|
|
|
|
static ZEND_FUNCTION(function_exists);
|
1999-09-21 05:28:37 +08:00
|
|
|
static ZEND_FUNCTION(leak);
|
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
|
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);
|
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);
|
2000-05-02 00:22:00 +08:00
|
|
|
static ZEND_FUNCTION(get_declared_classes);
|
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);
|
2000-06-09 23:40:37 +08:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
static ZEND_FUNCTION(zend_test_func);
|
|
|
|
#endif
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2000-03-13 02:08:46 +08:00
|
|
|
unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE };
|
|
|
|
unsigned char first_arg_allow_ref[] = { 1, BYREF_ALLOW };
|
|
|
|
unsigned char second_arg_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
|
|
|
|
unsigned char second_arg_allow_ref[] = { 2, BYREF_NONE, BYREF_ALLOW };
|
1999-09-22 17:57:42 +08:00
|
|
|
|
1999-09-20 20:24:39 +08:00
|
|
|
static zend_function_entry builtin_functions[] = {
|
|
|
|
ZEND_FE(zend_version, NULL)
|
1999-09-21 15:31:24 +08:00
|
|
|
ZEND_FE(func_num_args, NULL)
|
|
|
|
ZEND_FE(func_get_arg, NULL)
|
|
|
|
ZEND_FE(func_get_args, NULL)
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FE(strlen, NULL)
|
|
|
|
ZEND_FE(strcmp, NULL)
|
2000-02-09 01:19:43 +08:00
|
|
|
ZEND_FE(strncmp, NULL)
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FE(strcasecmp, NULL)
|
2000-07-26 19:32:15 +08:00
|
|
|
ZEND_FE(strncasecmp, NULL)
|
1999-09-22 17:57:42 +08:00
|
|
|
ZEND_FE(each, first_arg_force_ref)
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FE(error_reporting, NULL)
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FE(define, NULL)
|
|
|
|
ZEND_FE(defined, NULL)
|
|
|
|
ZEND_FE(get_class, NULL)
|
|
|
|
ZEND_FE(get_parent_class, NULL)
|
|
|
|
ZEND_FE(method_exists, NULL)
|
1999-12-15 05:15:24 +08:00
|
|
|
ZEND_FE(class_exists, NULL)
|
|
|
|
ZEND_FE(function_exists, NULL)
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FE(leak, NULL)
|
2000-02-13 09:22:11 +08:00
|
|
|
#ifdef ZEND_TEST_EXCEPTIONS
|
|
|
|
ZEND_FE(crash, NULL)
|
|
|
|
#endif
|
2000-03-11 00:36:30 +08:00
|
|
|
ZEND_FE(get_included_files, NULL)
|
2000-08-10 03:22:35 +08:00
|
|
|
ZEND_FALIAS(get_required_files, get_included_files, NULL)
|
1999-12-16 05:26:43 +08:00
|
|
|
ZEND_FE(is_subclass_of, NULL)
|
2000-02-27 01:54:00 +08:00
|
|
|
ZEND_FE(get_class_vars, NULL)
|
|
|
|
ZEND_FE(get_object_vars, NULL)
|
2000-03-24 01:47:28 +08:00
|
|
|
ZEND_FE(get_class_methods, NULL)
|
2000-06-02 20:36:54 +08:00
|
|
|
ZEND_FE(trigger_error, NULL)
|
|
|
|
ZEND_FALIAS(user_error, trigger_error, NULL)
|
|
|
|
ZEND_FE(set_error_handler, NULL)
|
2000-06-18 02:04:58 +08:00
|
|
|
ZEND_FE(restore_error_handler, NULL)
|
2000-05-02 00:22:00 +08:00
|
|
|
ZEND_FE(get_declared_classes, NULL)
|
2000-10-14 23:52:24 +08:00
|
|
|
ZEND_FE(get_defined_functions, NULL)
|
|
|
|
ZEND_FE(get_defined_vars, NULL)
|
2000-06-05 05:30:56 +08:00
|
|
|
ZEND_FE(create_function, NULL)
|
2000-07-19 04:32:39 +08:00
|
|
|
ZEND_FE(get_resource_type, NULL)
|
2000-06-09 23:40:37 +08:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
ZEND_FE(zend_test_func, NULL)
|
|
|
|
#endif
|
1999-09-20 20:24:39 +08:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int zend_startup_builtin_functions()
|
|
|
|
{
|
2000-06-13 04:22:17 +08:00
|
|
|
return zend_register_functions(builtin_functions, NULL, MODULE_PERSISTENT);
|
1999-09-20 20:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_FUNCTION(zend_version)
|
|
|
|
{
|
|
|
|
RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1, 1);
|
|
|
|
}
|
1999-09-20 21:00:35 +08:00
|
|
|
|
|
|
|
|
1999-09-21 15:31:24 +08:00
|
|
|
ZEND_FUNCTION(func_num_args)
|
1999-09-20 21:00:35 +08:00
|
|
|
{
|
|
|
|
void **p;
|
|
|
|
int arg_count;
|
|
|
|
|
2000-03-29 01:34:21 +08:00
|
|
|
p = EG(argument_stack).top_element-1-1;
|
|
|
|
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */
|
|
|
|
p -= 1+arg_count;
|
|
|
|
if (*p) {
|
2000-03-27 02:40:24 +08:00
|
|
|
zend_error(E_ERROR, "func_num_args(): Can't be used as a function parameter");
|
|
|
|
}
|
|
|
|
--p;
|
1999-09-20 21:00:35 +08:00
|
|
|
if (p>=EG(argument_stack).elements) {
|
|
|
|
RETURN_LONG((ulong) *p);
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 **z_requested_offset;
|
|
|
|
zval *arg;
|
|
|
|
long requested_offset;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &z_requested_offset)==FAILURE) {
|
1999-09-20 21:00:35 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_long_ex(z_requested_offset);
|
|
|
|
requested_offset = (*z_requested_offset)->value.lval;
|
|
|
|
|
2000-03-29 01:34:21 +08:00
|
|
|
p = EG(argument_stack).top_element-1-1;
|
|
|
|
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_get_arg(); */
|
|
|
|
p -= 1+arg_count;
|
|
|
|
if (*p) {
|
2000-03-27 02:40:24 +08:00
|
|
|
zend_error(E_ERROR, "func_get_arg(): Can't be used as a function parameter");
|
|
|
|
}
|
2000-03-29 01:34:21 +08:00
|
|
|
--p;
|
1999-09-20 21:00:35 +08:00
|
|
|
if (p<EG(argument_stack).elements) {
|
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;
|
|
|
|
}
|
|
|
|
arg_count = (ulong) *p;
|
|
|
|
|
2000-02-15 03:08:51 +08:00
|
|
|
if (requested_offset>=arg_count) {
|
|
|
|
zend_error(E_WARNING, "func_get_arg(): Argument %d 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);
|
|
|
|
}
|
|
|
|
|
1999-09-21 15:31:24 +08:00
|
|
|
|
|
|
|
ZEND_FUNCTION(func_get_args)
|
|
|
|
{
|
|
|
|
void **p;
|
|
|
|
int arg_count;
|
|
|
|
int i;
|
|
|
|
|
2000-03-29 01:34:21 +08:00
|
|
|
p = EG(argument_stack).top_element-1-1;
|
|
|
|
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_get_args(); */
|
|
|
|
p -= 1+arg_count;
|
|
|
|
if (*p) {
|
2000-03-27 02:40:24 +08:00
|
|
|
zend_error(E_ERROR, "func_get_args(): Can't be used as a function parameter");
|
|
|
|
}
|
2000-03-29 01:34:21 +08:00
|
|
|
--p;
|
1999-09-21 15:31:24 +08:00
|
|
|
|
|
|
|
if (p<EG(argument_stack).elements) {
|
|
|
|
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
arg_count = (ulong) *p;
|
|
|
|
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
/* {{{ proto int strlen(string str)
|
|
|
|
Get string length */
|
|
|
|
ZEND_FUNCTION(strlen)
|
|
|
|
{
|
|
|
|
zval **str;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
|
|
|
convert_to_string_ex(str);
|
|
|
|
RETVAL_LONG((*str)->value.str.len);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int strcmp(string str1, string str2)
|
|
|
|
Binary safe string comparison */
|
|
|
|
ZEND_FUNCTION(strcmp)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **s1, **s2;
|
1999-09-21 00:56:09 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_string_ex(s1);
|
|
|
|
convert_to_string_ex(s2);
|
2000-01-25 03:00:30 +08:00
|
|
|
RETURN_LONG(zend_binary_zval_strcmp(*s1,*s2));
|
1999-09-21 00:56:09 +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)
|
|
|
|
{
|
|
|
|
zval **s1, **s2, **s3;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-02-09 01:19:43 +08:00
|
|
|
}
|
|
|
|
convert_to_string_ex(s1);
|
|
|
|
convert_to_string_ex(s2);
|
|
|
|
convert_to_long_ex(s3);
|
|
|
|
RETURN_LONG(zend_binary_zval_strncmp(*s1,*s2,*s3));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
/* {{{ proto int strcasecmp(string str1, string str2)
|
|
|
|
Binary safe case-insensitive string comparison */
|
|
|
|
ZEND_FUNCTION(strcasecmp)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **s1, **s2;
|
1999-09-21 00:56:09 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_string_ex(s1);
|
|
|
|
convert_to_string_ex(s2);
|
2000-01-25 03:00:30 +08:00
|
|
|
RETURN_LONG(zend_binary_zval_strcasecmp(*s1, *s2));
|
1999-09-21 00:56:09 +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)
|
|
|
|
{
|
|
|
|
zval **s1, **s2, **s3;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
|
|
|
convert_to_string_ex(s1);
|
|
|
|
convert_to_string_ex(s2);
|
|
|
|
convert_to_long_ex(s3);
|
|
|
|
RETURN_LONG(zend_binary_zval_strncasecmp(*s1,*s2,*s3));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-09-21 00:56:09 +08:00
|
|
|
ZEND_FUNCTION(each)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **array,*entry,**entry_ptr, *tmp;
|
1999-09-21 00:56:09 +08:00
|
|
|
char *string_key;
|
|
|
|
ulong num_key;
|
|
|
|
zval **inserted_pointer;
|
|
|
|
HashTable *target_hash;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 00:56:09 +08:00
|
|
|
}
|
1999-10-04 21:27:12 +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 */
|
1999-10-02 07:31:39 +08:00
|
|
|
if (entry->is_ref) {
|
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);
|
1999-10-02 07:31:39 +08:00
|
|
|
tmp->is_ref=0;
|
1999-09-21 00:56:09 +08:00
|
|
|
tmp->refcount=0;
|
|
|
|
entry=tmp;
|
|
|
|
}
|
|
|
|
zend_hash_index_update(return_value->value.ht, 1, &entry, sizeof(zval *), NULL);
|
|
|
|
entry->refcount++;
|
2000-03-24 19:12:30 +08:00
|
|
|
zend_hash_update(return_value->value.ht, "value", sizeof("value"), &entry, sizeof(zval *), NULL);
|
1999-09-21 00:56:09 +08:00
|
|
|
entry->refcount++;
|
|
|
|
|
|
|
|
/* add the key elements */
|
|
|
|
switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) {
|
|
|
|
case HASH_KEY_IS_STRING:
|
|
|
|
add_get_index_string(return_value,0,string_key,(void **) &inserted_pointer,0);
|
|
|
|
break;
|
|
|
|
case HASH_KEY_IS_LONG:
|
|
|
|
add_get_index_long(return_value,0,num_key, (void **) &inserted_pointer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
zend_hash_update(return_value->value.ht, "key", sizeof("key"), inserted_pointer, sizeof(zval *), NULL);
|
|
|
|
(*inserted_pointer)->refcount++;
|
|
|
|
zend_hash_move_forward(target_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_FUNCTION(error_reporting)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **arg;
|
1999-09-21 00:56:09 +08:00
|
|
|
int old_error_reporting;
|
|
|
|
|
|
|
|
old_error_reporting = EG(error_reporting);
|
1999-12-19 06:23:23 +08:00
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-09-21 00:56:09 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
1999-12-19 06:23:23 +08:00
|
|
|
if (zend_get_parameters_ex(1,&arg) == FAILURE) {
|
1999-09-21 00:56:09 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_long_ex(arg);
|
|
|
|
EG(error_reporting)=(*arg)->value.lval;
|
1999-09-21 00:56:09 +08:00
|
|
|
break;
|
|
|
|
default:
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 00:56:09 +08:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|
1999-09-21 05:28:37 +08:00
|
|
|
|
|
|
|
ZEND_FUNCTION(define)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **var, **val, **non_cs;
|
1999-09-21 05:28:37 +08:00
|
|
|
int case_sensitive;
|
|
|
|
zend_constant c;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-09-21 05:28:37 +08:00
|
|
|
case 2:
|
1999-12-19 06:23:23 +08:00
|
|
|
if (zend_get_parameters_ex(2, &var, &val)==FAILURE) {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
case_sensitive = CONST_CS;
|
|
|
|
break;
|
|
|
|
case 3:
|
1999-12-19 06:23:23 +08:00
|
|
|
if (zend_get_parameters_ex(3, &var, &val, &non_cs)==FAILURE) {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_long_ex(non_cs);
|
|
|
|
if ((*non_cs)->value.lval) {
|
1999-09-21 05:28:37 +08:00
|
|
|
case_sensitive = 0;
|
|
|
|
} else {
|
|
|
|
case_sensitive = CONST_CS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 05:28:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-07-28 17:44:46 +08:00
|
|
|
|
1999-10-04 21:27:12 +08:00
|
|
|
switch((*val)->type) {
|
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;
|
|
|
|
default:
|
|
|
|
zend_error(E_WARNING,"Constants may only evaluate to scalar values");
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_string_ex(var);
|
1999-09-21 05:28:37 +08:00
|
|
|
|
1999-10-04 21:27:12 +08:00
|
|
|
c.value = **val;
|
1999-09-21 05:28:37 +08:00
|
|
|
zval_copy_ctor(&c.value);
|
2000-03-18 22:45:29 +08:00
|
|
|
c.flags = case_sensitive; /* non persistent */
|
1999-10-04 21:27:12 +08:00
|
|
|
c.name = zend_strndup((*var)->value.str.val, (*var)->value.str.len);
|
|
|
|
c.name_len = (*var)->value.str.len+1;
|
2000-07-28 17:44:46 +08:00
|
|
|
if(zend_register_constant(&c ELS_CC) == SUCCESS) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_FUNCTION(defined)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **var;
|
1999-09-21 05:28:37 +08:00
|
|
|
zval c;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &var)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_string_ex(var);
|
|
|
|
if (zend_get_constant((*var)->value.str.val, (*var)->value.str.len, &c)) {
|
1999-09-21 05:28:37 +08:00
|
|
|
zval_dtor(&c);
|
|
|
|
RETURN_LONG(1);
|
|
|
|
} else {
|
|
|
|
RETURN_LONG(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* {{{ 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)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **arg;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
if ((*arg)->type != IS_OBJECT) {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
RETURN_STRINGL((*arg)->value.obj.ce->name, (*arg)->value.obj.ce->name_length, 1);
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string get_parent_class(object object)
|
2000-02-28 02:41:19 +08:00
|
|
|
Retrieves the parent class name */
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(get_parent_class)
|
|
|
|
{
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **arg;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
if (((*arg)->type != IS_OBJECT) || !(*arg)->value.obj.ce->parent) {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-04 21:27:12 +08:00
|
|
|
RETURN_STRINGL((*arg)->value.obj.ce->parent->name, (*arg)->value.obj.ce->parent->name_length, 1);
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
1999-12-16 05:26:43 +08:00
|
|
|
|
|
|
|
/* {{{ proto bool is_subclass_of(object object, string class_name)
|
1999-12-16 06:37:05 +08:00
|
|
|
Returns true if the object has this class as one of its parents */
|
1999-12-16 05:26:43 +08:00
|
|
|
ZEND_FUNCTION(is_subclass_of)
|
|
|
|
{
|
|
|
|
zval **obj, **class_name;
|
|
|
|
char *lcname;
|
|
|
|
zend_class_entry *parent_ce = NULL;
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &obj, &class_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-12-16 05:26:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((*obj)->type != IS_OBJECT) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(class_name);
|
|
|
|
lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
|
|
|
|
zend_str_tolower(lcname, (*class_name)->value.str.len);
|
|
|
|
|
1999-12-16 06:37:05 +08:00
|
|
|
for (parent_ce = (*obj)->value.obj.ce->parent; parent_ce != NULL; parent_ce = parent_ce->parent) {
|
1999-12-16 05:26:43 +08:00
|
|
|
if (!strcmp(parent_ce->name, lcname)) {
|
|
|
|
efree(lcname);
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-12-16 06:37:05 +08:00
|
|
|
}
|
1999-12-16 05:26:43 +08:00
|
|
|
efree(lcname);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-09-21 05:28:37 +08:00
|
|
|
|
2000-02-27 01:54:00 +08:00
|
|
|
/* {{{ proto array get_class_vars(string class_name)
|
|
|
|
Returns an array of default properties of the class */
|
|
|
|
ZEND_FUNCTION(get_class_vars)
|
|
|
|
{
|
|
|
|
zval **class_name;
|
|
|
|
char *lcname;
|
|
|
|
zend_class_entry *ce;
|
|
|
|
zval *tmp;
|
2000-02-27 05:12:44 +08:00
|
|
|
CLS_FETCH();
|
2000-02-27 01:54:00 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(class_name);
|
|
|
|
lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
|
|
|
|
zend_str_tolower(lcname, (*class_name)->value.str.len);
|
|
|
|
|
|
|
|
if (zend_hash_find(CG(class_table), lcname, (*class_name)->value.str.len+1, (void **)&ce)==FAILURE) {
|
|
|
|
efree(lcname);
|
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
efree(lcname);
|
|
|
|
array_init(return_value);
|
|
|
|
zend_hash_copy(return_value->value.ht, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto array get_object_vars(object obj)
|
|
|
|
Returns an array of object properties */
|
|
|
|
ZEND_FUNCTION(get_object_vars)
|
|
|
|
{
|
|
|
|
zval **obj;
|
|
|
|
zval *tmp;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &obj) == FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-02-27 01:54:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((*obj)->type != IS_OBJECT) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
zend_hash_copy(return_value->value.ht, (*obj)->value.obj.properties,
|
|
|
|
(copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-03-24 01:47:28 +08:00
|
|
|
/* {{{ proto array get_class_methods(string class_name)
|
|
|
|
Returns an array of class methods' names */
|
|
|
|
ZEND_FUNCTION(get_class_methods)
|
|
|
|
{
|
|
|
|
zval **class_name;
|
|
|
|
zval *method_name;
|
|
|
|
char *lcname;
|
|
|
|
zend_class_entry *ce;
|
|
|
|
char *string_key;
|
|
|
|
ulong num_key;
|
|
|
|
int key_type;
|
|
|
|
CLS_FETCH();
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-03-24 01:47:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(class_name);
|
|
|
|
lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
|
|
|
|
zend_str_tolower(lcname, (*class_name)->value.str.len);
|
|
|
|
|
|
|
|
if (zend_hash_find(CG(class_table), lcname, (*class_name)->value.str.len+1, (void **)&ce)==FAILURE) {
|
|
|
|
efree(lcname);
|
2000-03-24 02:31:18 +08:00
|
|
|
RETURN_NULL();
|
2000-03-24 01:47:28 +08:00
|
|
|
} else {
|
|
|
|
efree(lcname);
|
|
|
|
array_init(return_value);
|
|
|
|
zend_hash_internal_pointer_reset(&ce->function_table);
|
|
|
|
while ((key_type = zend_hash_get_current_key(&ce->function_table, &string_key, &num_key)) != HASH_KEY_NON_EXISTANT) {
|
|
|
|
if (key_type == HASH_KEY_IS_STRING) {
|
|
|
|
MAKE_STD_ZVAL(method_name);
|
2000-09-05 22:58:14 +08:00
|
|
|
ZVAL_STRING(method_name, string_key, 1);
|
2000-03-24 01:47:28 +08:00
|
|
|
zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
|
|
|
|
}
|
|
|
|
zend_hash_move_forward(&ce->function_table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
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)
|
|
|
|
{
|
1999-12-15 05:15:24 +08:00
|
|
|
zval **klass, **method_name;
|
|
|
|
char *lcname;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &klass, &method_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
1999-12-15 05:15:24 +08:00
|
|
|
if ((*klass)->type != IS_OBJECT) {
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-15 05:15:24 +08:00
|
|
|
convert_to_string_ex(method_name);
|
1999-12-16 00:54:46 +08:00
|
|
|
lcname = estrndup((*method_name)->value.str.val, (*method_name)->value.str.len);
|
1999-12-15 05:15:24 +08:00
|
|
|
zend_str_tolower(lcname, (*method_name)->value.str.len);
|
|
|
|
if(zend_hash_exists(&(*klass)->value.obj.ce->function_table, lcname, (*method_name)->value.str.len+1)) {
|
|
|
|
efree(lcname);
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
1999-12-15 05:15:24 +08:00
|
|
|
efree(lcname);
|
1999-09-21 05:28:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-12-15 05:15:24 +08:00
|
|
|
/* {{{ proto bool class_exists(string classname)
|
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)
|
|
|
|
{
|
|
|
|
zval **class_name;
|
|
|
|
char *lcname;
|
|
|
|
CLS_FETCH();
|
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
convert_to_string_ex(class_name);
|
1999-12-15 23:59:04 +08:00
|
|
|
lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
|
1999-12-15 05:15:24 +08:00
|
|
|
zend_str_tolower(lcname, (*class_name)->value.str.len);
|
|
|
|
if (zend_hash_exists(CG(class_table), lcname, (*class_name)->value.str.len+1)) {
|
|
|
|
efree(lcname);
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
efree(lcname);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool function_exists(string function_name)
|
|
|
|
Checks if the function exists */
|
|
|
|
ZEND_FUNCTION(function_exists)
|
|
|
|
{
|
|
|
|
zval **function_name;
|
|
|
|
char *lcname;
|
1999-12-23 02:49:23 +08:00
|
|
|
int retval;
|
1999-12-15 05:15:24 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &function_name)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
convert_to_string_ex(function_name);
|
1999-12-15 23:59:04 +08:00
|
|
|
lcname = estrndup((*function_name)->value.str.val, (*function_name)->value.str.len);
|
1999-12-15 05:15:24 +08:00
|
|
|
zend_str_tolower(lcname, (*function_name)->value.str.len);
|
1999-12-23 02:49:23 +08:00
|
|
|
|
|
|
|
retval = zend_hash_exists(EG(function_table), lcname, (*function_name)->value.str.len+1);
|
|
|
|
efree(lcname);
|
|
|
|
|
|
|
|
RETURN_BOOL(retval);
|
1999-12-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-02-13 09:22:11 +08:00
|
|
|
|
1999-09-21 05:28:37 +08:00
|
|
|
ZEND_FUNCTION(leak)
|
|
|
|
{
|
|
|
|
int leakbytes=3;
|
1999-10-04 21:27:12 +08:00
|
|
|
zval **leak;
|
1999-09-21 05:28:37 +08:00
|
|
|
|
1999-12-19 06:23:23 +08:00
|
|
|
if (ZEND_NUM_ARGS()>=1) {
|
|
|
|
if (zend_get_parameters_ex(1, &leak)==SUCCESS) {
|
1999-10-04 21:27:12 +08:00
|
|
|
convert_to_long_ex(leak);
|
|
|
|
leakbytes = (*leak)->value.lval;
|
1999-09-21 05:28:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
emalloc(leakbytes);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
1999-12-04 22:26:26 +08:00
|
|
|
static int copy_import_use_file(zend_file_handle *fh, zval *array)
|
|
|
|
{
|
|
|
|
if (fh->filename) {
|
|
|
|
char *extension_start;
|
|
|
|
|
|
|
|
extension_start = strstr(fh->filename, zend_uv.import_use_extension);
|
|
|
|
if (extension_start) {
|
|
|
|
*extension_start = 0;
|
|
|
|
if (fh->opened_path) {
|
|
|
|
add_assoc_string(array, fh->filename, fh->opened_path, 1);
|
|
|
|
} else {
|
|
|
|
add_assoc_stringl(array, fh->filename, "N/A", sizeof("N/A")-1, 1);
|
|
|
|
}
|
|
|
|
*extension_start = zend_uv.import_use_extension[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2000-05-02 00:22:00 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
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));
|
|
|
|
while(zend_hash_get_current_key(&EG(included_files), &entry,NULL) == HASH_KEY_IS_STRING) {
|
|
|
|
add_next_index_string(return_value,entry,0);
|
|
|
|
zend_hash_move_forward(&EG(included_files));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* zend_hash_apply_with_argument(&EG(included_files), (apply_func_arg_t) copy_import_use_file, return_value); */
|
1999-12-04 22:26:26 +08:00
|
|
|
}
|
2000-04-19 21:15:13 +08:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2000-06-02 20:36:54 +08:00
|
|
|
/* {{{ proto void trigger_error(string messsage [, 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
|
|
|
{
|
|
|
|
int error_type = E_USER_NOTICE;
|
|
|
|
zval **z_error_type, **z_error_message;
|
|
|
|
|
|
|
|
switch(ZEND_NUM_ARGS()) {
|
|
|
|
case 1:
|
|
|
|
if (zend_get_parameters_ex(1, &z_error_message)==FAILURE) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (zend_get_parameters_ex(2, &z_error_message, &z_error_type)==FAILURE) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
|
|
|
convert_to_long_ex(z_error_type);
|
|
|
|
error_type = (*z_error_type)->value.lval;
|
|
|
|
switch (error_type) {
|
|
|
|
case E_USER_ERROR:
|
|
|
|
case E_USER_WARNING:
|
|
|
|
case E_USER_NOTICE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
zend_error(E_WARNING, "Invalid error type specified");
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2000-09-05 20:08:41 +08:00
|
|
|
default:
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-04-19 21:15:13 +08:00
|
|
|
}
|
|
|
|
convert_to_string_ex(z_error_message);
|
2000-10-01 00:24:53 +08:00
|
|
|
zend_error(error_type, "%s", (*z_error_message)->value.str.val);
|
2000-04-19 21:15:13 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2000-04-19 23:08:06 +08:00
|
|
|
|
|
|
|
|
2000-06-13 04:31:02 +08:00
|
|
|
/* {{{ proto string set_error_handler(string error_handler)
|
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
|
|
|
{
|
|
|
|
zval **error_handler;
|
2000-06-13 04:31:02 +08:00
|
|
|
zend_bool had_orig_error_handler=0;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &error_handler)==FAILURE) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(error_handler);
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
2000-06-02 20:36:54 +08:00
|
|
|
if (Z_STRLEN_PP(error_handler)==0) { /* unset user-defined handler */
|
|
|
|
FREE_ZVAL(EG(user_error_handler));
|
|
|
|
EG(user_error_handler) = NULL;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-19 23:08:06 +08:00
|
|
|
*EG(user_error_handler) = **error_handler;
|
|
|
|
zval_copy_ctor(EG(user_error_handler));
|
|
|
|
|
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)) {
|
|
|
|
zval_ptr_dtor(&EG(user_error_handler));
|
|
|
|
}
|
|
|
|
if (zend_ptr_stack_num_elements(&EG(user_error_handlers))==0) {
|
|
|
|
EG(user_error_handler) = NULL;
|
|
|
|
} else {
|
|
|
|
EG(user_error_handler) = zend_ptr_stack_pop(&EG(user_error_handlers));
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-09 23:40:37 +08:00
|
|
|
static int copy_class_name(zend_class_entry *ce, 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 *);
|
|
|
|
|
|
|
|
if (hash_key->nKeyLength==0 || hash_key->arKey[0]!=0) {
|
|
|
|
add_next_index_stringl(array, ce->name, ce->name_length, 1);
|
|
|
|
}
|
2000-05-02 00:22:00 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* {{{ proto array get_declared_classes(void)
|
|
|
|
Returns an array of all declared classes. */
|
|
|
|
ZEND_FUNCTION(get_declared_classes)
|
|
|
|
{
|
|
|
|
CLS_FETCH();
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-05-02 00:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
2000-06-10 04:18:16 +08:00
|
|
|
zend_hash_apply_with_arguments(CG(class_table), (apply_func_args_t)copy_class_name, 1, return_value);
|
2000-05-02 00:22:00 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-06-03 09:49:49 +08:00
|
|
|
|
2000-10-14 23:52:24 +08:00
|
|
|
static int copy_function_name(zend_function *func, int num_args, va_list args, zend_hash_key *hash_key)
|
|
|
|
{
|
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) {
|
|
|
|
add_next_index_stringl(internal_ar, hash_key->arKey, hash_key->nKeyLength, 1);
|
|
|
|
} else if (func->type == ZEND_USER_FUNCTION) {
|
|
|
|
add_next_index_stringl(user_ar, hash_key->arKey, hash_key->nKeyLength, 1);
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* {{{ 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;
|
2000-10-14 23:52:24 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
2000-10-15 03:48:53 +08:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(internal);
|
|
|
|
MAKE_STD_ZVAL(user);
|
|
|
|
|
|
|
|
array_init(internal);
|
|
|
|
array_init(user);
|
2000-10-14 23:52:24 +08:00
|
|
|
array_init(return_value);
|
|
|
|
|
2000-10-15 03:48:53 +08:00
|
|
|
zend_hash_apply_with_arguments(EG(function_table), (apply_func_args_t)copy_function_name, 2, internal, user);
|
|
|
|
|
|
|
|
if (zend_hash_add(return_value->value.ht, "internal", sizeof("internal"), (void **)&internal, sizeof(zval *), NULL) == FAILURE) {
|
|
|
|
zend_error(E_WARNING, "Cannot add internal functions to return value from get_defined_functions()");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_hash_add(return_value->value.ht, "user", sizeof("user"), (void **)&user, sizeof(zval *), NULL) == FAILURE) {
|
|
|
|
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
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ 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)
|
|
|
|
{
|
2000-11-21 23:29:02 +08:00
|
|
|
zval *tmp;
|
2000-10-14 23:52:24 +08:00
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
2000-11-21 23:29:02 +08:00
|
|
|
zend_hash_copy(return_value->value.ht, EG(active_symbol_table),
|
|
|
|
(copy_ctor_func_t)zval_add_ref, &tmp, sizeof(zval *));
|
2000-10-14 23:52:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-06-03 09:49:49 +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
|
|
|
{
|
|
|
|
char *eval_code, *function_name;
|
|
|
|
int eval_code_length, function_name_length;
|
|
|
|
zval **z_function_args, **z_function_code;
|
|
|
|
int retval;
|
2000-09-13 03:47:25 +08:00
|
|
|
char *eval_name;
|
2000-06-03 09:49:49 +08:00
|
|
|
CLS_FETCH();
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &z_function_args, &z_function_code)==FAILURE) {
|
2000-07-15 04:00:24 +08:00
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
2000-06-03 09:49:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(z_function_args);
|
|
|
|
convert_to_string_ex(z_function_code);
|
|
|
|
|
|
|
|
eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME)
|
|
|
|
+Z_STRLEN_PP(z_function_args)
|
|
|
|
+2 /* for the args parentheses */
|
|
|
|
+2 /* for the curly braces */
|
|
|
|
+Z_STRLEN_PP(z_function_code);
|
|
|
|
|
|
|
|
eval_code = (char *) emalloc(eval_code_length);
|
|
|
|
sprintf(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(%s){%s}", Z_STRVAL_PP(z_function_args), Z_STRVAL_PP(z_function_code));
|
|
|
|
|
2000-09-13 03:47:25 +08:00
|
|
|
eval_name = zend_make_compiled_string_description("runtime-created function");
|
|
|
|
retval = zend_eval_string(eval_code, NULL, eval_name CLS_CC ELS_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) {
|
|
|
|
zend_function *func;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
function_add_ref(func);
|
|
|
|
|
|
|
|
function_name = (char *) emalloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG);
|
|
|
|
|
|
|
|
do {
|
|
|
|
sprintf(function_name, "%clambda_%d", 0, ++EG(lambda_count));
|
2000-06-03 10:02:09 +08:00
|
|
|
function_name_length = strlen(function_name+1)+1;
|
2000-06-03 09:49:49 +08:00
|
|
|
} while (zend_hash_add(EG(function_table), function_name, function_name_length+1, func, sizeof(zend_function), NULL)==FAILURE);
|
|
|
|
zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME));
|
|
|
|
RETURN_STRINGL(function_name, function_name_length, 0);
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
2000-08-26 22:45:29 +08:00
|
|
|
#endif
|
2000-07-15 04:00:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
ZEND_FUNCTION(get_resource_type)
|
|
|
|
{
|
|
|
|
char *resource_type;
|
|
|
|
zval **z_resource_type;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &z_resource_type)==FAILURE) {
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Z_TYPE_PP(z_resource_type) != IS_RESOURCE) {
|
|
|
|
zend_error(E_WARNING, "Supplied argument is not a valid resource handle");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_type = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(z_resource_type));
|
|
|
|
if (resource_type) {
|
|
|
|
RETURN_STRING(resource_type, 1);
|
|
|
|
} else {
|
|
|
|
RETURN_STRING("Unknown", 1);
|
|
|
|
}
|
|
|
|
}
|