Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug #34199 (if($obj)/if(!$obj) inconsistency)

  • Loading branch information...
commit 9d1f2f30d3f1b04b8fa65ff2f21853872265b7ac 1 parent 9a74c68
Dmitry Stogov authored
View
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)
View
17 Zend/tests/bug34199.phpt
@@ -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
View
18 Zend/zend_execute.h
@@ -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 {
View
2  Zend/zend_operators.c
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.