1999-04-17 00:37:12 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 08:18:22 +00:00
|
|
|
| PHP Version 5 |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2007-12-31 07:17:19 +00:00
|
|
|
| Copyright (c) 1997-2008 The PHP Group |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Author: Rasmus Lerdorf <rasmus@php.net> |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-07-24 01:40:02 +00:00
|
|
|
*/
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/* $Id$ */
|
2000-07-24 01:40:02 +00:00
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "php.h"
|
2002-07-24 09:55:11 +00:00
|
|
|
#include "php_incomplete_class.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
/* {{{ proto string gettype(mixed var)
|
|
|
|
Returns the type of the variable */
|
|
|
|
PHP_FUNCTION(gettype)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2005-12-05 22:54:01 +00:00
|
|
|
zval **arg;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
|
|
|
|
return;
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
|
|
|
|
switch (Z_TYPE_PP(arg)) {
|
|
|
|
case IS_NULL:
|
|
|
|
RETVAL_STRING("NULL", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_BOOL:
|
|
|
|
RETVAL_STRING("boolean", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_LONG:
|
|
|
|
RETVAL_STRING("integer", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_DOUBLE:
|
|
|
|
RETVAL_STRING("double", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_STRING:
|
|
|
|
RETVAL_STRING("string", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_ARRAY:
|
|
|
|
RETVAL_STRING("array", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_OBJECT:
|
|
|
|
RETVAL_STRING("object", 1);
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
int res_len;
|
|
|
|
|
|
|
|
res_len = sizeof("object of type ")-1 + Z_OBJCE_P(arg)->name_length;
|
2007-02-24 02:17:47 +00:00
|
|
|
spprintf(&result, 0, "object of type %s", Z_OBJCE_P(arg)->name);
|
2002-01-09 23:47:46 +00:00
|
|
|
RETVAL_STRINGL(result, res_len, 0);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2005-06-14 21:32:29 +00:00
|
|
|
case IS_RESOURCE:
|
|
|
|
{
|
|
|
|
char *type_name;
|
|
|
|
type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC);
|
|
|
|
if (type_name) {
|
|
|
|
RETVAL_STRING("resource", 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
default:
|
|
|
|
RETVAL_STRING("unknown type", 1);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
/* {{{ proto bool settype(mixed var, string type)
|
|
|
|
Set the type of the variable */
|
|
|
|
PHP_FUNCTION(settype)
|
|
|
|
{
|
2008-06-20 13:02:33 +00:00
|
|
|
zval **var;
|
|
|
|
char *type;
|
|
|
|
int type_len = 0;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &var, &type, &type_len) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (!strcasecmp(type, "integer")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_long(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "int")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_long(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "float")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_double(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "double")) { /* deprecated */
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_double(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "string")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_string(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "array")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_array(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "object")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_object(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "bool")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_boolean(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "boolean")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_boolean(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "null")) {
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_null(*var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "resource")) {
|
2002-08-24 01:19:28 +00:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot convert to resource type");
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
2002-08-24 01:19:28 +00:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type");
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETVAL_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int intval(mixed var [, int base])
|
|
|
|
Get the integer value of a variable using the optional base for the conversion */
|
|
|
|
PHP_FUNCTION(intval)
|
|
|
|
{
|
2008-06-20 13:02:33 +00:00
|
|
|
zval **num;
|
|
|
|
long arg_base;
|
2002-01-09 23:47:46 +00:00
|
|
|
int base;
|
|
|
|
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
|
|
|
case 1:
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
base = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zl", &num, &arg_base) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2008-06-20 13:02:33 +00:00
|
|
|
base = arg_base;
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2005-03-11 02:11:44 +00:00
|
|
|
RETVAL_ZVAL(*num, 1, 0);
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_long_base(return_value, base);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto float floatval(mixed var)
|
|
|
|
Get the float value of a variable */
|
|
|
|
PHP_FUNCTION(floatval)
|
|
|
|
{
|
2005-12-05 22:54:01 +00:00
|
|
|
zval **num;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2005-03-11 02:11:44 +00:00
|
|
|
RETVAL_ZVAL(*num, 1, 0);
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_double(return_value);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string strval(mixed var)
|
|
|
|
Get the string value of a variable */
|
|
|
|
PHP_FUNCTION(strval)
|
|
|
|
{
|
2005-04-15 22:46:37 +00:00
|
|
|
zval **num, *tmp;
|
2004-03-14 22:59:04 +00:00
|
|
|
zval expr_copy;
|
|
|
|
int use_copy;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2005-03-11 02:11:44 +00:00
|
|
|
zend_make_printable_zval(*num, &expr_copy, &use_copy);
|
2004-03-14 22:59:04 +00:00
|
|
|
if (use_copy) {
|
2005-03-11 02:11:44 +00:00
|
|
|
tmp = &expr_copy;
|
|
|
|
RETVAL_ZVAL(tmp, 0, 0);
|
2004-03-14 22:59:04 +00:00
|
|
|
} else {
|
2005-04-15 22:46:37 +00:00
|
|
|
RETVAL_ZVAL(*num, 1, 0);
|
2004-03-14 22:59:04 +00:00
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
|
|
|
|
{
|
2005-12-05 22:54:01 +00:00
|
|
|
zval **arg;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Z_TYPE_PP(arg) == type) {
|
2002-07-24 09:55:11 +00:00
|
|
|
if (type == IS_OBJECT) {
|
|
|
|
zend_class_entry *ce;
|
2005-05-25 10:57:40 +00:00
|
|
|
if(Z_OBJ_HT_PP(arg)->get_class_entry == NULL) {
|
|
|
|
/* if there's no get_class_entry it's not a PHP object, so it can't be INCOMPLETE_CLASS */
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2002-07-24 09:55:11 +00:00
|
|
|
ce = Z_OBJCE_PP(arg);
|
|
|
|
if (!strcmp(ce->name, INCOMPLETE_CLASS)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-04-01 08:54:44 +00:00
|
|
|
if (type == IS_RESOURCE) {
|
|
|
|
char *type_name;
|
|
|
|
type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC);
|
|
|
|
if (!type_name) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto bool is_null(mixed var)
|
|
|
|
Returns true if variable is null */
|
|
|
|
PHP_FUNCTION(is_null)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_resource(mixed var)
|
|
|
|
Returns true if variable is a resource */
|
|
|
|
PHP_FUNCTION(is_resource)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_bool(mixed var)
|
|
|
|
Returns true if variable is a boolean */
|
|
|
|
PHP_FUNCTION(is_bool)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_BOOL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_long(mixed var)
|
|
|
|
Returns true if variable is a long (integer) */
|
|
|
|
PHP_FUNCTION(is_long)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_float(mixed var)
|
|
|
|
Returns true if variable is float point*/
|
|
|
|
PHP_FUNCTION(is_float)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_string(mixed var)
|
|
|
|
Returns true if variable is a string */
|
|
|
|
PHP_FUNCTION(is_string)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_array(mixed var)
|
|
|
|
Returns true if variable is an array */
|
|
|
|
PHP_FUNCTION(is_array)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_object(mixed var)
|
|
|
|
Returns true if variable is an object */
|
|
|
|
PHP_FUNCTION(is_object)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_numeric(mixed value)
|
|
|
|
Returns true if value is a number or a numeric string */
|
|
|
|
PHP_FUNCTION(is_numeric)
|
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Z_TYPE_PP(arg)) {
|
|
|
|
case IS_LONG:
|
|
|
|
case IS_DOUBLE:
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_STRING:
|
2006-12-26 16:45:39 +00:00
|
|
|
if (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0)) {
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_scalar(mixed value)
|
|
|
|
Returns true if value is a scalar */
|
|
|
|
PHP_FUNCTION(is_scalar)
|
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
|
2008-06-20 13:02:33 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Z_TYPE_PP(arg)) {
|
|
|
|
case IS_BOOL:
|
|
|
|
case IS_DOUBLE:
|
|
|
|
case IS_LONG:
|
|
|
|
case IS_STRING:
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]])
|
|
|
|
Returns true if var is callable. */
|
|
|
|
PHP_FUNCTION(is_callable)
|
|
|
|
{
|
2008-10-21 22:08:38 +00:00
|
|
|
zval *var, **callable_name = NULL;
|
2008-02-02 14:03:13 +00:00
|
|
|
char *name;
|
2002-01-09 23:47:46 +00:00
|
|
|
zend_bool retval;
|
2008-02-02 13:58:31 +00:00
|
|
|
zend_bool syntax_only = 0;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-02-02 13:58:31 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|bZ", &var,
|
|
|
|
&syntax_only, &callable_name) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-02 13:58:31 +00:00
|
|
|
syntax_only = syntax_only ? IS_CALLABLE_CHECK_SYNTAX_ONLY : 0;
|
|
|
|
if (ZEND_NUM_ARGS() > 2) {
|
2008-08-02 04:46:07 +00:00
|
|
|
retval = zend_is_callable(var, syntax_only, &name TSRMLS_CC);
|
2008-02-02 14:03:13 +00:00
|
|
|
zval_dtor(*callable_name);
|
|
|
|
ZVAL_STRING(*callable_name, name, 0);
|
2002-01-09 23:47:46 +00:00
|
|
|
} else {
|
2008-08-02 04:46:07 +00:00
|
|
|
retval = zend_is_callable(var, syntax_only, NULL TSRMLS_CC);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_BOOL(retval);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2001-06-05 13:12:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-05 13:12:10 +00:00
|
|
|
*/
|