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:12:20 +00:00
|
|
|
| Copyright (c) 1997-2008 The PHP Group |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 13:10:10 +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 13:10:10 +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
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto string gettype(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns the type of the variable */
|
|
|
|
PHP_FUNCTION(gettype)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2005-12-05 22:53:34 +00:00
|
|
|
zval **arg;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2008-08-19 02:51:28 +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:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("NULL", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_BOOL:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("boolean", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_LONG:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("integer", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_DOUBLE:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("double", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_STRING:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("string", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-11 23:36:07 +00:00
|
|
|
case IS_UNICODE:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("unicode", 1);
|
2005-08-11 23:36:07 +00:00
|
|
|
break;
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_ARRAY:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("array", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_OBJECT:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("object", 1);
|
2002-01-09 23:47:46 +00:00
|
|
|
/*
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
int res_len;
|
|
|
|
|
|
|
|
res_len = sizeof("object of type ")-1 + Z_OBJCE_P(arg)->name_length;
|
2007-02-24 16:25:58 +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) {
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_STRING("resource", 1);
|
2005-06-14 21:32:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
default:
|
2005-08-23 12:53:31 +00:00
|
|
|
RETVAL_ASCII_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
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool settype(mixed var, string type) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Set the type of the variable */
|
|
|
|
PHP_FUNCTION(settype)
|
|
|
|
{
|
2008-08-19 02:51:28 +00:00
|
|
|
zval **var;
|
2002-01-09 23:47:46 +00:00
|
|
|
char *new_type;
|
2008-08-19 02:51:28 +00:00
|
|
|
int new_type_len;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &var, &new_type, &new_type_len) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(new_type, "integer")) {
|
|
|
|
convert_to_long(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "int")) {
|
|
|
|
convert_to_long(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "float")) {
|
|
|
|
convert_to_double(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "double")) { /* deprecated */
|
|
|
|
convert_to_double(*var);
|
2006-09-25 01:37:55 +00:00
|
|
|
} else if (!strcasecmp(new_type, "binary")) { /* explicit binary cast */
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_string(*var);
|
2006-09-25 01:37:55 +00:00
|
|
|
} else if (!strcasecmp(new_type, "string")) { /* runtime string type */
|
|
|
|
if (UG(unicode)) {
|
|
|
|
convert_to_unicode(*var);
|
|
|
|
} else {
|
|
|
|
convert_to_string(*var);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(new_type, "unicode")) { /* explicit unicode cast */
|
2006-09-24 18:23:47 +00:00
|
|
|
convert_to_unicode(*var);
|
2002-01-09 23:47:46 +00:00
|
|
|
} else if (!strcasecmp(new_type, "array")) {
|
|
|
|
convert_to_array(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "object")) {
|
|
|
|
convert_to_object(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "bool")) {
|
|
|
|
convert_to_boolean(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "boolean")) {
|
|
|
|
convert_to_boolean(*var);
|
|
|
|
} else if (!strcasecmp(new_type, "null")) {
|
|
|
|
convert_to_null(*var);
|
|
|
|
} else if (!strcasecmp(new_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;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto int intval(mixed var [, int base]) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Get the integer value of a variable using the optional base for the conversion */
|
|
|
|
PHP_FUNCTION(intval)
|
|
|
|
{
|
2008-08-19 02:51:28 +00:00
|
|
|
zval **num;
|
|
|
|
long arg_base = 0;
|
|
|
|
int base = 10;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|l", &num, &arg_base) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() == 2) {
|
|
|
|
base = arg_base;
|
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_long_base(return_value, base);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto float floatval(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Get the float value of a variable */
|
|
|
|
PHP_FUNCTION(floatval)
|
|
|
|
{
|
2008-03-29 22:02:20 +00:00
|
|
|
zval **num;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-29 22:02:20 +00:00
|
|
|
RETVAL_ZVAL(*num, 1, 0);
|
|
|
|
convert_to_double(return_value);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto string strval(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
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-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2006-01-17 12:18:53 +00:00
|
|
|
if (UG(unicode)) {
|
|
|
|
zend_make_unicode_zval(*num, &expr_copy, &use_copy);
|
|
|
|
} else {
|
2007-05-17 17:29:09 +00:00
|
|
|
zend_make_string_zval(*num, &expr_copy, &use_copy);
|
2006-01-17 12:18:53 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2007-05-31 21:36:56 +00:00
|
|
|
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
|
2002-01-09 23:47:46 +00:00
|
|
|
{
|
2006-09-24 18:23:47 +00:00
|
|
|
zval *arg;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
if (Z_TYPE_P(arg) == type) {
|
2002-07-24 09:55:11 +00:00
|
|
|
if (type == IS_OBJECT) {
|
|
|
|
zend_class_entry *ce;
|
2006-09-24 18:23:47 +00:00
|
|
|
|
|
|
|
if(Z_OBJ_HT_P(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 */
|
2005-05-25 10:57:40 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2006-09-24 18:23:47 +00:00
|
|
|
ce = Z_OBJCE_P(arg);
|
|
|
|
|
|
|
|
if (ce->name_length != sizeof(INCOMPLETE_CLASS) - 1) {
|
|
|
|
/* We can get away with this because INCOMPLETE_CLASS is ascii and has a 1:1 relationship with unicode */
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else if (UG(unicode)) {
|
2006-10-08 18:00:44 +00:00
|
|
|
#ifndef PHP_WIN32
|
2006-10-07 04:45:42 +00:00
|
|
|
U_STRING_DECL(uIncompleteClass, (INCOMPLETE_CLASS), sizeof(INCOMPLETE_CLASS) - 1);
|
|
|
|
U_STRING_INIT(uIncompleteClass, (INCOMPLETE_CLASS), sizeof(INCOMPLETE_CLASS) - 1);
|
2006-09-24 18:23:47 +00:00
|
|
|
|
|
|
|
if (!memcmp(ce->name.u, uIncompleteClass, UBYTES(sizeof(INCOMPLETE_CLASS)))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2006-10-08 18:00:44 +00:00
|
|
|
#else /* WIN32 -- U_STRING_DECL breaks under Win32 with string macros */
|
2006-10-09 02:55:38 +00:00
|
|
|
char *ascii_name = zend_unicode_to_ascii(ce->name.u, ce->name_length TSRMLS_CC);
|
2006-10-08 18:00:44 +00:00
|
|
|
|
|
|
|
if (ascii_name) {
|
|
|
|
if (memcmp(INCOMPLETE_CLASS, ascii_name, sizeof(INCOMPLETE_CLASS) - 1) == 0) {
|
|
|
|
efree(ascii_name);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
efree(ascii_name);
|
|
|
|
}
|
|
|
|
/* Non-ascii class name means it can't be INCOMPLETE_CLASS and is therefore okay */
|
|
|
|
#endif
|
2006-09-24 18:23:47 +00:00
|
|
|
} else {
|
|
|
|
if (!memcmp(ce->name.s, INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-07-24 09:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-01 08:54:44 +00:00
|
|
|
if (type == IS_RESOURCE) {
|
|
|
|
char *type_name;
|
2006-09-24 18:23:47 +00:00
|
|
|
type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_P(arg) TSRMLS_CC);
|
2004-04-01 08:54:44 +00:00
|
|
|
if (!type_name) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-05-31 21:36:56 +00:00
|
|
|
/* }}} */
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_null(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is null */
|
|
|
|
PHP_FUNCTION(is_null)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_resource(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is a resource */
|
|
|
|
PHP_FUNCTION(is_resource)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_bool(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is a boolean */
|
|
|
|
PHP_FUNCTION(is_bool)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_BOOL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_long(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is a long (integer) */
|
|
|
|
PHP_FUNCTION(is_long)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_float(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is float point*/
|
|
|
|
PHP_FUNCTION(is_float)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_binary(mixed var) U
|
2006-03-17 14:29:05 +00:00
|
|
|
Returns true if variable is a native (binary) string */
|
|
|
|
PHP_FUNCTION(is_binary)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_string(mixed var) U
|
2006-03-17 23:00:20 +00:00
|
|
|
Returns true if variable is a Unicode or binary string */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_string)
|
|
|
|
{
|
2008-08-19 02:51:28 +00:00
|
|
|
zval *arg;
|
2006-03-17 23:00:20 +00:00
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) {
|
|
|
|
return;
|
2006-03-17 23:00:20 +00:00
|
|
|
}
|
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (Z_TYPE_P(arg) == IS_UNICODE || Z_TYPE_P(arg) == IS_STRING) {
|
2006-03-17 23:00:20 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_unicode(mixed var) U
|
2005-08-13 10:16:04 +00:00
|
|
|
Returns true if variable is a unicode string */
|
|
|
|
PHP_FUNCTION(is_unicode)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_UNICODE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_buffer(mixed var) U
|
2005-08-13 21:18:47 +00:00
|
|
|
Returns true if variable is a native, unicode or binary string */
|
2005-08-13 10:16:04 +00:00
|
|
|
PHP_FUNCTION(is_buffer)
|
|
|
|
{
|
2008-08-19 02:51:28 +00:00
|
|
|
zval *arg;
|
2005-08-13 10:16:04 +00:00
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) {
|
|
|
|
return;
|
2005-08-13 10:16:04 +00:00
|
|
|
}
|
|
|
|
|
2008-08-19 02:51:28 +00:00
|
|
|
if (Z_TYPE_P(arg) == IS_STRING || Z_TYPE_P(arg) == IS_UNICODE) {
|
2005-08-13 10:16:04 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_array(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is an array */
|
|
|
|
PHP_FUNCTION(is_array)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_object(mixed var) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if variable is an object */
|
|
|
|
PHP_FUNCTION(is_object)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_numeric(mixed value) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if value is a number or a numeric string */
|
|
|
|
PHP_FUNCTION(is_numeric)
|
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
int result;
|
|
|
|
|
2008-08-19 02:51:28 +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:
|
|
|
|
result = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0);
|
|
|
|
if (result == IS_LONG || result == IS_DOUBLE) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-08-23 12:53:31 +00:00
|
|
|
case IS_UNICODE:
|
|
|
|
result = is_numeric_unicode(Z_USTRVAL_PP(arg), Z_USTRLEN_PP(arg), NULL, NULL, 0);
|
|
|
|
if (result == IS_LONG || result == IS_DOUBLE) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
default:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-24 18:23:47 +00:00
|
|
|
/* {{{ proto bool is_scalar(mixed value) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if value is a scalar */
|
|
|
|
PHP_FUNCTION(is_scalar)
|
|
|
|
{
|
|
|
|
zval **arg;
|
2008-08-19 02:51:28 +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:
|
2005-08-11 23:36:07 +00:00
|
|
|
case IS_UNICODE:
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-10-06 20:11:25 +00:00
|
|
|
/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]]) U
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if var is callable. */
|
|
|
|
PHP_FUNCTION(is_callable)
|
|
|
|
{
|
2008-10-21 22:06:49 +00:00
|
|
|
zval *var, **callable_name = NULL;
|
2005-08-22 12:22:16 +00:00
|
|
|
zval name;
|
2002-01-09 23:47:46 +00:00
|
|
|
zend_bool retval;
|
2006-10-06 20:11:25 +00:00
|
|
|
zend_bool syntax_only = 0;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2006-10-06 20:11:25 +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:11:12 +00:00
|
|
|
syntax_only = syntax_only ? IS_CALLABLE_CHECK_SYNTAX_ONLY : 0;
|
2006-10-06 20:11:25 +00:00
|
|
|
if (ZEND_NUM_ARGS() > 2) {
|
2008-08-02 04:40:45 +00:00
|
|
|
retval = zend_is_callable(var, syntax_only, &name TSRMLS_CC);
|
2006-10-06 20:11:25 +00:00
|
|
|
REPLACE_ZVAL_VALUE(callable_name, &name, 0);
|
2002-01-09 23:47:46 +00:00
|
|
|
} else {
|
2008-08-02 04:40:45 +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
|
|
|
*/
|