mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
- Move some more Zend internal functions from PHP
This commit is contained in:
parent
7e686b1b95
commit
68217ef564
1 changed files with 155 additions and 0 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "zend_builtin_functions.h"
|
||||
#include "zend_operators.h"
|
||||
#include "zend_variables.h"
|
||||
#include "zend_constants.h"
|
||||
|
||||
static ZEND_FUNCTION(zend_version);
|
||||
static ZEND_FUNCTION(zend_num_args);
|
||||
|
@ -32,6 +33,12 @@ static ZEND_FUNCTION(strcmp);
|
|||
static ZEND_FUNCTION(strcasecmp);
|
||||
static ZEND_FUNCTION(each);
|
||||
static ZEND_FUNCTION(error_reporting);
|
||||
static ZEND_FUNCTION(define);
|
||||
static ZEND_FUNCTION(defined);
|
||||
static ZEND_FUNCTION(get_class);
|
||||
static ZEND_FUNCTION(get_parent_class);
|
||||
static ZEND_FUNCTION(method_exists);
|
||||
static ZEND_FUNCTION(leak);
|
||||
|
||||
static zend_function_entry builtin_functions[] = {
|
||||
ZEND_FE(zend_version, NULL)
|
||||
|
@ -42,6 +49,12 @@ static zend_function_entry builtin_functions[] = {
|
|||
ZEND_FE(strcasecmp, NULL)
|
||||
ZEND_FE(each, NULL)
|
||||
ZEND_FE(error_reporting, NULL)
|
||||
ZEND_FE(define, NULL)
|
||||
ZEND_FE(defined, NULL)
|
||||
ZEND_FE(get_class, NULL)
|
||||
ZEND_FE(get_parent_class, NULL)
|
||||
ZEND_FE(method_exists, NULL)
|
||||
ZEND_FE(leak, NULL)
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -230,3 +243,145 @@ ZEND_FUNCTION(error_reporting)
|
|||
|
||||
RETVAL_LONG(old_error_reporting);
|
||||
}
|
||||
|
||||
ZEND_FUNCTION(define)
|
||||
{
|
||||
zval *var, *val, *non_cs;
|
||||
int case_sensitive;
|
||||
zend_constant c;
|
||||
ELS_FETCH();
|
||||
|
||||
switch(ARG_COUNT(ht)) {
|
||||
case 2:
|
||||
if (getParameters(ht, 2, &var, &val)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
case_sensitive = CONST_CS;
|
||||
break;
|
||||
case 3:
|
||||
if (getParameters(ht, 3, &var, &val, &non_cs)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
convert_to_long(non_cs);
|
||||
if (non_cs->value.lval) {
|
||||
case_sensitive = 0;
|
||||
} else {
|
||||
case_sensitive = CONST_CS;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
}
|
||||
switch(val->type) {
|
||||
case IS_LONG:
|
||||
case IS_DOUBLE:
|
||||
case IS_STRING:
|
||||
case IS_BOOL:
|
||||
case IS_RESOURCE:
|
||||
break;
|
||||
default:
|
||||
zend_error(E_WARNING,"Constants may only evaluate to scalar values");
|
||||
RETURN_FALSE;
|
||||
break;
|
||||
}
|
||||
convert_to_string(var);
|
||||
|
||||
c.value = *val;
|
||||
zval_copy_ctor(&c.value);
|
||||
c.flags = case_sensitive | ~CONST_PERSISTENT; /* non persistent */
|
||||
c.name = zend_strndup(var->value.str.val, var->value.str.len);
|
||||
c.name_len = var->value.str.len+1;
|
||||
zend_register_constant(&c ELS_CC);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
|
||||
ZEND_FUNCTION(defined)
|
||||
{
|
||||
zval *var;
|
||||
zval c;
|
||||
|
||||
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &var)==FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_string(var);
|
||||
if (zend_get_constant(var->value.str.val, var->value.str.len, &c)) {
|
||||
zval_dtor(&c);
|
||||
RETURN_LONG(1);
|
||||
} else {
|
||||
RETURN_LONG(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto string get_class(object object)
|
||||
Retrieves the class name ...
|
||||
*/
|
||||
ZEND_FUNCTION(get_class)
|
||||
{
|
||||
zval *arg;
|
||||
|
||||
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (arg->type != IS_OBJECT) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL(arg->value.obj.ce->name, arg->value.obj.ce->name_length, 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string get_parent_class(object object)
|
||||
Retrieves the parent class name ...
|
||||
*/
|
||||
ZEND_FUNCTION(get_parent_class)
|
||||
{
|
||||
zval *arg;
|
||||
|
||||
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if ((arg->type != IS_OBJECT) || !arg->value.obj.ce->parent) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRINGL(arg->value.obj.ce->parent->name, arg->value.obj.ce->parent->name_length, 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool method_exists(object object, string method)
|
||||
Checks if the class method exists ...
|
||||
*/
|
||||
ZEND_FUNCTION(method_exists)
|
||||
{
|
||||
zval *arg1, *arg2;
|
||||
|
||||
if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &arg1, &arg2)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (arg1->type != IS_OBJECT) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
convert_to_string(arg2);
|
||||
if(zend_hash_exists(&arg1->value.obj.ce->function_table, arg2->value.str.val, arg2->value.str.len+1)) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_FUNCTION(leak)
|
||||
{
|
||||
int leakbytes=3;
|
||||
zval *leak;
|
||||
|
||||
if (ARG_COUNT(ht)>=1) {
|
||||
if (getParameters(ht, 1, &leak)==SUCCESS) {
|
||||
convert_to_long(leak);
|
||||
leakbytes = leak->value.lval;
|
||||
}
|
||||
}
|
||||
|
||||
emalloc(leakbytes);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue