Commit: 74b4ef5036ccdb2d71a514732c6b521aa2aa62d3 Author: Jille Timmermans <ji...@quis.cx> Wed, 6 Jun 2012 22:34:51 +0200 Parents: c22a29b57639178581210ec377ea4e9909f828c9 Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=74b4ef5036ccdb2d71a514732c6b521aa2aa62d3 Log: Implement boolval() with a test Changed paths: M ext/standard/basic_functions.c M ext/standard/php_type.h A ext/standard/tests/general_functions/boolval.phpt M ext/standard/type.c Diff: 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) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php