mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Fixed bug #34199 (if($obj)/if(!$obj) inconsistency)
This commit is contained in:
parent
9a74c68a4c
commit
9d1f2f30d3
2
NEWS
2
NEWS
@ -46,6 +46,8 @@ PHP NEWS
|
||||
(Dmitry)
|
||||
- Fixed bug #34257 (lib64 not handled correctly in ming extension). (Marcus)
|
||||
- Fixed bug #34221 (Compiling xmlrpc as shared fails other parts). (Jani)
|
||||
- Fixed bug #34199 (if($obj)/if(!$obj) inconsistency because of cast handler).
|
||||
(Dmitry, Alex)
|
||||
- Fixed bug #34191 (ob_gzhandler does not enforce trailing \0). (Ilia)
|
||||
- Fixed bug #34156 (memory usage remains elevated after memory limit is
|
||||
reached). (Ilia)
|
||||
|
17
Zend/tests/bug34199.phpt
Executable file
17
Zend/tests/bug34199.phpt
Executable file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Bug #34199 (if($obj)/if(!$obj) inconsistency because of cast handler)
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = "<root></root>";
|
||||
$xml = simplexml_load_string($xml);
|
||||
$kids = $xml->children();
|
||||
var_dump((bool)$kids);
|
||||
if($kids) echo "bug\n"; else echo "ok\n";
|
||||
if(!$kids) echo "ok\n"; else echo "bug\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(false)
|
||||
ok
|
||||
ok
|
@ -99,6 +99,24 @@ static inline int i_zend_is_true(zval *op)
|
||||
case IS_OBJECT:
|
||||
if(IS_ZEND_STD_OBJECT(*op)) {
|
||||
TSRMLS_FETCH();
|
||||
|
||||
if (Z_OBJ_HT_P(op)->cast_object) {
|
||||
zval tmp;
|
||||
if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_BOOL, 1 TSRMLS_CC) == SUCCESS) {
|
||||
result = Z_LVAL(tmp);
|
||||
break;
|
||||
}
|
||||
} else if (Z_OBJ_HT_P(op)->get) {
|
||||
zval *tmp = Z_OBJ_HT_P(op)->get(op TSRMLS_CC);
|
||||
if(Z_TYPE_P(tmp) != IS_OBJECT) {
|
||||
/* for safety - avoid loop */
|
||||
convert_to_boolean(tmp);
|
||||
result = Z_LVAL_P(tmp);
|
||||
zval_ptr_dtor(&tmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(EG(ze1_compatibility_mode)) {
|
||||
result = (zend_hash_num_elements(Z_OBJPROP_P(op))?1:0);
|
||||
} else {
|
||||
|
@ -482,7 +482,7 @@ ZEND_API void convert_to_boolean(zval *op)
|
||||
zend_bool retval = 1;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
convert_object_to_type(op, IS_BOOL, convert_to_double);
|
||||
convert_object_to_type(op, IS_BOOL, convert_to_boolean);
|
||||
|
||||
if (op->type == IS_BOOL) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user