From 2f988a1f34329a82489f170c281037c0d3e2bc7b Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Wed, 18 Apr 2012 15:46:11 +0200 Subject: [PATCH 1/3] Implement boolval() (like strval()) --- ext/standard/basic_functions.c | 5 +++++ ext/standard/php_type.h | 1 + ext/standard/type.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 528e4f65b96e..63d40efde440 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 1927deded8d5..12e916b886ae 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/type.c b/ext/standard/type.c index 543fdeac1034..5d112fbc83c9 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 **num; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) { + return; + } + + RETVAL_ZVAL(*num, 1, 0); + convert_to_boolean(return_value); +} +/* }}} */ + /* {{{ proto string strval(mixed var) Get the string value of a variable */ PHP_FUNCTION(strval) From a5d113e799b03b59996c8621b3e034df421b1f27 Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Thu, 19 Apr 2012 12:06:26 +0200 Subject: [PATCH 2/3] Don't call a boolean-variable `num` --- ext/standard/type.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/type.c b/ext/standard/type.c index 5d112fbc83c9..e56261050cef 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -180,14 +180,14 @@ PHP_FUNCTION(floatval) Get the boolean value of a variable */ PHP_FUNCTION(boolval) { - zval **num; + zval **val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &val) == FAILURE) { return; } - RETVAL_ZVAL(*num, 1, 0); - convert_to_boolean(return_value); + RETVAL_ZVAL(*val, 1, 0); + convert_to_boolean_ex(return_value); } /* }}} */ From 90a3d4712785d0768d8d988dd8de95b2737fd938 Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Thu, 19 Apr 2012 12:20:04 +0200 Subject: [PATCH 3/3] Revert unwanted change in previous (a5d11e3) commit --- ext/standard/type.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/type.c b/ext/standard/type.c index e56261050cef..59d7314bba74 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -187,7 +187,7 @@ PHP_FUNCTION(boolval) } RETVAL_ZVAL(*val, 1, 0); - convert_to_boolean_ex(return_value); + convert_to_boolean(return_value); } /* }}} */