Skip to content

Commit 753c336

Browse files
committed
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
2 parents 07d0eab + 6af01ed commit 753c336

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212
(Nikita Popov)
1313

1414
- Core:
15+
. Added boolval(). (Jille Timmermans).
1516
. Fixed bug #61681 (Malformed grammar). (Nikita Popov, Etienne, Laruence).
1617
. Fixed bug #61038 (unpack("a5", "str\0\0") does not work as expected).
1718
(srgoogleguy, Gustavo)

ext/standard/basic_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_strval, 0)
25222522
ZEND_ARG_INFO(0, var)
25232523
ZEND_END_ARG_INFO()
25242524

2525+
ZEND_BEGIN_ARG_INFO(arginfo_boolval, 0)
2526+
ZEND_ARG_INFO(0, var)
2527+
ZEND_END_ARG_INFO()
2528+
25252529
ZEND_BEGIN_ARG_INFO(arginfo_is_null, 0)
25262530
ZEND_ARG_INFO(0, var)
25272531
ZEND_END_ARG_INFO()
@@ -3045,6 +3049,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
30453049
PHP_FE(floatval, arginfo_floatval)
30463050
PHP_FALIAS(doubleval, floatval, arginfo_floatval)
30473051
PHP_FE(strval, arginfo_strval)
3052+
PHP_FE(boolval, arginfo_boolval)
30483053
PHP_FE(gettype, arginfo_gettype)
30493054
PHP_FE(settype, arginfo_settype)
30503055
PHP_FE(is_null, arginfo_is_null)

ext/standard/php_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
PHP_FUNCTION(intval);
2525
PHP_FUNCTION(floatval);
2626
PHP_FUNCTION(strval);
27+
PHP_FUNCTION(boolval);
2728
PHP_FUNCTION(gettype);
2829
PHP_FUNCTION(settype);
2930
PHP_FUNCTION(is_null);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Testing boolval()
3+
--FILE--
4+
<?php
5+
var_dump(boolval(false));
6+
var_dump(boolval(NULL));
7+
var_dump(boolval(""));
8+
var_dump(boolval(0));
9+
var_dump(boolval(array()));
10+
11+
var_dump(boolval(true));
12+
var_dump(boolval("abc"));
13+
var_dump(boolval(0.5));
14+
var_dump(boolval(100));
15+
var_dump(boolval(new stdClass()));
16+
var_dump(boolval(STDIN));
17+
?>
18+
--EXPECTF--
19+
bool(false)
20+
bool(false)
21+
bool(false)
22+
bool(false)
23+
bool(false)
24+
bool(true)
25+
bool(true)
26+
bool(true)
27+
bool(true)
28+
bool(true)
29+
bool(true)

ext/standard/type.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ PHP_FUNCTION(floatval)
176176
}
177177
/* }}} */
178178

179+
/* {{{ proto bool boolval(mixed var)
180+
Get the boolean value of a variable */
181+
PHP_FUNCTION(boolval)
182+
{
183+
zval **val;
184+
185+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &val) == FAILURE) {
186+
return;
187+
}
188+
189+
RETVAL_ZVAL(*val, 1, 0);
190+
convert_to_boolean(return_value);
191+
}
192+
/* }}} */
193+
179194
/* {{{ proto string strval(mixed var)
180195
Get the string value of a variable */
181196
PHP_FUNCTION(strval)

0 commit comments

Comments
 (0)