1999-04-17 00:37:12 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-19 16:33:14 +00:00
|
|
|
| PHP Version 7 |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 15:27:30 +00:00
|
|
|
| Copyright (c) 1997-2015 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
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *arg;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
switch (Z_TYPE_P(arg)) {
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_NULL:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("NULL");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-30 14:32:42 +00:00
|
|
|
case IS_FALSE:
|
|
|
|
case IS_TRUE:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("boolean");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
2014-08-25 17:24:55 +00:00
|
|
|
case IS_LONG:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("integer");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_DOUBLE:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("double");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_STRING:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("string");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_ARRAY:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("array");
|
2002-01-09 23:47:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_OBJECT:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("object");
|
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 02:17:47 +00:00
|
|
|
spprintf(&result, 0, "object of type %s", Z_OBJCE_P(arg)->name);
|
2014-07-22 03:28:20 +00:00
|
|
|
RETVAL_STRINGL(result, res_len);
|
2014-07-22 16:55:54 +00:00
|
|
|
efree(result);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2005-06-14 21:32:29 +00:00
|
|
|
case IS_RESOURCE:
|
|
|
|
{
|
2014-12-13 22:06:14 +00:00
|
|
|
const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg));
|
2010-11-19 16:03:00 +00:00
|
|
|
|
2005-06-14 21:32:29 +00:00
|
|
|
if (type_name) {
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("resource");
|
2005-06-14 21:32:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
default:
|
2014-02-13 13:54:23 +00:00
|
|
|
RETVAL_STRING("unknown type");
|
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)
|
|
|
|
{
|
2014-02-21 13:22:02 +00:00
|
|
|
zval *var;
|
2008-06-20 13:02:33 +00:00
|
|
|
char *type;
|
2014-08-27 13:31:48 +00:00
|
|
|
size_t type_len = 0;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &var, &type, &type_len) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 11:40:40 +00:00
|
|
|
ZVAL_DEREF(var);
|
2014-06-05 12:04:11 +00:00
|
|
|
SEPARATE_ZVAL_NOREF(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
if (!strcasecmp(type, "integer")) {
|
2014-08-25 19:51:49 +00:00
|
|
|
convert_to_long(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "int")) {
|
2014-08-25 19:51:49 +00:00
|
|
|
convert_to_long(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "float")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_double(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "double")) { /* deprecated */
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_double(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "string")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_string(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "array")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_array(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "object")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_object(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "bool")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_boolean(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "boolean")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_boolean(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "null")) {
|
2014-02-21 13:22:02 +00:00
|
|
|
convert_to_null(var);
|
2008-06-20 13:02:33 +00:00
|
|
|
} else if (!strcasecmp(type, "resource")) {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, E_WARNING, "Cannot convert to resource type");
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
2014-12-13 22:06:14 +00:00
|
|
|
php_error_docref(NULL, 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)
|
|
|
|
{
|
2014-02-21 16:35:40 +00:00
|
|
|
zval *num;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_long base = 10;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-07-11 12:32:20 +00:00
|
|
|
if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 2) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
#ifndef FAST_ZPP
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &num, &base) == FAILURE) {
|
2014-07-11 12:32:20 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2014-07-11 12:32:20 +00:00
|
|
|
#else
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 2)
|
|
|
|
Z_PARAM_ZVAL(num)
|
|
|
|
Z_PARAM_OPTIONAL
|
2014-08-25 17:24:55 +00:00
|
|
|
Z_PARAM_LONG(base)
|
2014-07-11 12:32:20 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
#endif
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-02-21 16:35:40 +00:00
|
|
|
RETVAL_ZVAL(num, 1, 0);
|
2014-10-24 11:00:33 +00:00
|
|
|
convert_to_long_base(return_value, (int)base);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto float floatval(mixed var)
|
|
|
|
Get the float value of a variable */
|
|
|
|
PHP_FUNCTION(floatval)
|
|
|
|
{
|
2014-02-21 16:35:40 +00:00
|
|
|
zval *num;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &num) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 16:35:40 +00:00
|
|
|
RETVAL_ZVAL(num, 1, 0);
|
2002-01-09 23:47:46 +00:00
|
|
|
convert_to_double(return_value);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-06-06 20:34:51 +00:00
|
|
|
/* {{{ proto bool boolval(mixed var)
|
|
|
|
Get the boolean value of a variable */
|
|
|
|
PHP_FUNCTION(boolval)
|
|
|
|
{
|
2014-02-21 16:35:40 +00:00
|
|
|
zval *val;
|
2012-06-06 20:34:51 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &val) == FAILURE) {
|
2012-06-06 20:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
RETURN_BOOL(zend_is_true(val));
|
2012-06-06 20:34:51 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-01-09 23:47:46 +00:00
|
|
|
/* {{{ proto string strval(mixed var)
|
|
|
|
Get the string value of a variable */
|
|
|
|
PHP_FUNCTION(strval)
|
|
|
|
{
|
2014-04-21 15:51:15 +00:00
|
|
|
zval *num;
|
2015-01-12 16:26:12 +00:00
|
|
|
|
|
|
|
#ifndef FAST_ZPP
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &num) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2015-01-12 16:26:12 +00:00
|
|
|
#else
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
|
|
|
Z_PARAM_ZVAL(num)
|
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
#endif
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-04-21 15:51:15 +00:00
|
|
|
RETVAL_STR(zval_get_string(num));
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-07-11 12:32:20 +00:00
|
|
|
static inline void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
|
2002-01-09 23:47:46 +00:00
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *arg;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-07-11 12:32:20 +00:00
|
|
|
#ifndef FAST_ZPP
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
|
2002-01-09 23:47:46 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2014-03-27 09:39:09 +00:00
|
|
|
ZVAL_DEREF(arg);
|
2014-07-11 12:32:20 +00:00
|
|
|
#else
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
|
|
|
Z_PARAM_ZVAL_DEREF(arg)
|
|
|
|
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
|
|
|
|
#endif
|
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
if (Z_TYPE_P(arg) == type) {
|
2002-07-24 09:55:11 +00:00
|
|
|
if (type == IS_OBJECT) {
|
2014-10-09 11:58:14 +00:00
|
|
|
zend_class_entry *ce = Z_OBJCE_P(arg);
|
2015-01-03 09:22:58 +00:00
|
|
|
if (ce->name->len == sizeof(INCOMPLETE_CLASS) - 1
|
2015-03-16 12:53:54 +00:00
|
|
|
&& !memcmp(ce->name->val, INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS) - 1)) {
|
2002-07-24 09:55:11 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2014-06-26 10:29:25 +00:00
|
|
|
} else if (type == IS_RESOURCE) {
|
2014-12-13 22:06:14 +00:00
|
|
|
const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg));
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto bool is_null(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is null
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_null)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_resource(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is a resource
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_resource)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_bool(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is a boolean
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_bool)
|
|
|
|
{
|
2014-04-30 14:32:42 +00:00
|
|
|
zval *arg;
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
|
2014-04-30 14:32:42 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZVAL_DEREF(arg);
|
|
|
|
RETURN_BOOL(Z_TYPE_P(arg) == IS_FALSE || Z_TYPE_P(arg) == IS_TRUE);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 21:26:16 +00:00
|
|
|
/* {{{ proto bool is_int(mixed var)
|
2014-12-14 20:57:07 +00:00
|
|
|
Returns true if variable is an integer
|
2014-08-28 19:53:32 +00:00
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2014-12-14 21:26:16 +00:00
|
|
|
PHP_FUNCTION(is_int)
|
2002-01-09 23:47:46 +00:00
|
|
|
{
|
2014-08-25 17:24:55 +00:00
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_float(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is float point
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_float)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_string(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is a string
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_string)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_array(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is an array
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
PHP_FUNCTION(is_array)
|
|
|
|
{
|
|
|
|
php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool is_object(mixed var)
|
2014-08-28 19:53:32 +00:00
|
|
|
Returns true if variable is an object
|
|
|
|
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
|
2002-01-09 23:47:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *arg;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2015-01-12 16:26:12 +00:00
|
|
|
#ifndef FAST_ZPP
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2015-01-12 16:26:12 +00:00
|
|
|
#else
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
|
|
|
Z_PARAM_ZVAL(arg)
|
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
#endif
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
switch (Z_TYPE_P(arg)) {
|
2014-08-25 17:24:55 +00:00
|
|
|
case IS_LONG:
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_DOUBLE:
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IS_STRING:
|
2014-08-25 17:24:55 +00:00
|
|
|
if (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(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)
|
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *arg;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-07-11 12:32:20 +00:00
|
|
|
#ifndef FAST_ZPP
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
|
2008-06-20 13:02:33 +00:00
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2014-07-11 12:32:20 +00:00
|
|
|
#else
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
|
|
|
Z_PARAM_ZVAL(arg)
|
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
#endif
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-02-13 13:54:23 +00:00
|
|
|
switch (Z_TYPE_P(arg)) {
|
2014-04-30 14:32:42 +00:00
|
|
|
case IS_FALSE:
|
|
|
|
case IS_TRUE:
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_DOUBLE:
|
2014-08-25 17:24:55 +00:00
|
|
|
case IS_LONG:
|
2002-01-09 23:47:46 +00:00
|
|
|
case IS_STRING:
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-01-03 09:22:58 +00:00
|
|
|
/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]])
|
2002-01-09 23:47:46 +00:00
|
|
|
Returns true if var is callable. */
|
|
|
|
PHP_FUNCTION(is_callable)
|
|
|
|
{
|
2014-02-13 13:54:23 +00:00
|
|
|
zval *var, *callable_name = NULL;
|
2014-02-25 12:03:34 +00:00
|
|
|
zend_string *name;
|
2009-04-02 09:56:33 +00:00
|
|
|
char *error;
|
2002-01-09 23:47:46 +00:00
|
|
|
zend_bool retval;
|
2008-02-02 13:58:31 +00:00
|
|
|
zend_bool syntax_only = 0;
|
2009-04-02 09:56:33 +00:00
|
|
|
int check_flags = 0;
|
2002-01-09 23:47:46 +00:00
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|bz/", &var,
|
2008-02-02 13:58:31 +00:00
|
|
|
&syntax_only, &callable_name) == FAILURE) {
|
|
|
|
return;
|
2002-01-09 23:47:46 +00:00
|
|
|
}
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2009-04-02 09:56:33 +00:00
|
|
|
if (syntax_only) {
|
|
|
|
check_flags |= IS_CALLABLE_CHECK_SYNTAX_ONLY;
|
|
|
|
}
|
2008-02-02 13:58:31 +00:00
|
|
|
if (ZEND_NUM_ARGS() > 2) {
|
2014-12-13 22:06:14 +00:00
|
|
|
retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, &error);
|
2014-02-13 13:54:23 +00:00
|
|
|
zval_dtor(callable_name);
|
2014-04-15 17:56:30 +00:00
|
|
|
//??? is it necessary to be consistent with old PHP ("\0" support)
|
2014-04-16 18:42:37 +00:00
|
|
|
if (UNEXPECTED(name->len) != strlen(name->val)) {
|
|
|
|
ZVAL_STRINGL(callable_name, name->val, strlen(name->val));
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_string_release(name);
|
2014-04-16 18:42:37 +00:00
|
|
|
} else {
|
|
|
|
ZVAL_STR(callable_name, name);
|
|
|
|
}
|
2002-01-09 23:47:46 +00:00
|
|
|
} else {
|
2014-12-13 22:06:14 +00:00
|
|
|
retval = zend_is_callable_ex(var, NULL, check_flags, NULL, NULL, &error);
|
2009-04-02 09:56:33 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
/* ignore errors */
|
|
|
|
efree(error);
|
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
|
|
|
*/
|