summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDavid Soria Parra <dsp@php.net>2012-06-07 07:38:17 (GMT)
committerDavid Soria Parra <dsp@php.net>2012-06-07 07:38:17 (GMT)
commit753c3367c044fa54eac9b7233f72b58e63b2ac67 (patch)
treee5604af3ff82e8ff24b37c2da8e2d41533b96fc8 /ext
parent07d0eab204c19ceca259319c38af79e64b61aecd (diff)
parent6af01ed5a0a2be2aa2fb7bd39ad1e3c286d54cf5 (diff)
downloadphp-753c3367c044fa54eac9b7233f72b58e63b2ac67.tar.gz
Merge branch 'pull-request/60'
By David Soria Parra (1) and Jille Timmermans (1) * pull-request/60: NEWS entry for boolval() Implement boolval() with a test
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/basic_functions.c5
-rw-r--r--ext/standard/php_type.h1
-rw-r--r--ext/standard/tests/general_functions/boolval.phpt29
-rw-r--r--ext/standard/type.c15
4 files changed, 50 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 528e4f6..63d40ef 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2522,6 +2522,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_strval, 0)
ZEND_ARG_INFO(0, var)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_boolval, 0)
+ ZEND_ARG_INFO(0, var)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_is_null, 0)
ZEND_ARG_INFO(0, var)
ZEND_END_ARG_INFO()
@@ -3045,6 +3049,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(floatval, arginfo_floatval)
PHP_FALIAS(doubleval, floatval, arginfo_floatval)
PHP_FE(strval, arginfo_strval)
+ PHP_FE(boolval, arginfo_boolval)
PHP_FE(gettype, arginfo_gettype)
PHP_FE(settype, arginfo_settype)
PHP_FE(is_null, arginfo_is_null)
diff --git a/ext/standard/php_type.h b/ext/standard/php_type.h
index 1927ded..12e916b 100644
--- a/ext/standard/php_type.h
+++ b/ext/standard/php_type.h
@@ -24,6 +24,7 @@
PHP_FUNCTION(intval);
PHP_FUNCTION(floatval);
PHP_FUNCTION(strval);
+PHP_FUNCTION(boolval);
PHP_FUNCTION(gettype);
PHP_FUNCTION(settype);
PHP_FUNCTION(is_null);
diff --git a/ext/standard/tests/general_functions/boolval.phpt b/ext/standard/tests/general_functions/boolval.phpt
new file mode 100644
index 0000000..9d0eac4
--- /dev/null
+++ b/ext/standard/tests/general_functions/boolval.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Testing boolval()
+--FILE--
+<?php
+ var_dump(boolval(false));
+ var_dump(boolval(NULL));
+ var_dump(boolval(""));
+ var_dump(boolval(0));
+ var_dump(boolval(array()));
+
+ var_dump(boolval(true));
+ var_dump(boolval("abc"));
+ var_dump(boolval(0.5));
+ var_dump(boolval(100));
+ var_dump(boolval(new stdClass()));
+ var_dump(boolval(STDIN));
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/standard/type.c b/ext/standard/type.c
index 543fdea..59d7314b 100644
--- a/ext/standard/type.c
+++ b/ext/standard/type.c
@@ -176,6 +176,21 @@ PHP_FUNCTION(floatval)
}
/* }}} */
+/* {{{ proto bool boolval(mixed var)
+ Get the boolean value of a variable */
+PHP_FUNCTION(boolval)
+{
+ zval **val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &val) == FAILURE) {
+ return;
+ }
+
+ RETVAL_ZVAL(*val, 1, 0);
+ convert_to_boolean(return_value);
+}
+/* }}} */
+
/* {{{ proto string strval(mixed var)
Get the string value of a variable */
PHP_FUNCTION(strval)