summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-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
5 files changed, 51 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 87ecf08..3adefae 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ PHP NEWS
(Nikita Popov)
- Core:
+ . Added boolval(). (Jille Timmermans).
. Fixed bug #61681 (Malformed grammar). (Nikita Popov, Etienne, Laruence).
. Fixed bug #61038 (unpack("a5", "str\0\0") does not work as expected).
(srgoogleguy, Gustavo)
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)