cvs: ZendEngine2 / zend_object_handlers.c /tests bug44899.phpt bug44899_2.phpt

[email protected] ("Felipe Pena")
Newsgroups php.zend-engine.cvs
Message-ID <cvsfelipe1209775014@cvsserver>
felipe		Sat May  3 00:36:54 2008 UTC

  Added files:                 
    /ZendEngine2/tests	bug44899.phpt bug44899_2.phpt 

  Modified files:              
    /ZendEngine2	zend_object_handlers.c 
  Log:
  - Fixed bug #44899 (__isset usage changes behavior of empty()) (patch by Etienne Kneuss)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.199&r2=1.200&diff_format=u
Index: ZendEngine2/zend_object_handlers.c
diff -u ZendEngine2/zend_object_handlers.c:1.199 ZendEngine2/zend_object_handlers.c:1.200
--- ZendEngine2/zend_object_handlers.c:1.199	Tue Apr 29 08:15:49 2008
+++ ZendEngine2/zend_object_handlers.c	Sat May  3 00:36:54 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_object_handlers.c,v 1.199 2008/04/29 08:15:49 dmitry Exp $ */
+/* $Id: zend_object_handlers.c,v 1.200 2008/05/03 00:36:54 felipe Exp $ */
 
 #include "zend.h"
 #include "zend_globals.h"
@@ -1148,14 +1148,20 @@
 			if (rv) {
 				result = zend_is_true(rv);
 				zval_ptr_dtor(&rv);
-				if (has_set_exists && result && !EG(exception) && zobj->ce->__get && !guard->in_get) {
-					guard->in_get = 1;
-					rv = zend_std_call_getter(object, member TSRMLS_CC);
-					guard->in_get = 0;
-					if (rv) {
-						Z_ADDREF_P(rv);
-						result = i_zend_is_true(rv);
-						zval_ptr_dtor(&rv);
+				if (has_set_exists && result) {
+					if (!EG(exception) && zobj->ce->__get && !guard->in_get) {
+						guard->in_get = 1;
+						rv = zend_std_call_getter(object, member TSRMLS_CC);
+						guard->in_get = 0;
+						if (rv) {
+							Z_ADDREF_P(rv);
+							result = i_zend_is_true(rv);
+							zval_ptr_dtor(&rv);
+						} else {
+							result = 0;
+						}
+					} else {
+						result = 0;
 					}
 				}
 			}

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug44899.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug44899.phpt
+++ ZendEngine2/tests/bug44899.phpt
--TEST--
Bug #44899 (__isset usage changes behavior of empty())
--FILE--
<?php

class myclass
{
	private $_data = array();

	function __construct($data)
	{
		$this->_data = $data;
	}

	function __isset($field_name)
	{
		return isset($this->_data[$field_name]);
	}
}

$arr = array('foo' => '');

$myclass = new myclass($arr) ;

echo (isset($myclass->foo)) ? 'isset' : 'not isset';
echo "\n";
echo (empty($myclass->foo)) ? 'empty' : 'not empty';
echo "\n";
echo ($myclass->foo) ? 'not empty' : 'empty';
echo "\n";

?>
--EXPECTF--
isset
empty

Notice: Undefined property: myclass::$foo in %s on line %d
empty

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug44899_2.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug44899_2.phpt
+++ ZendEngine2/tests/bug44899_2.phpt
--TEST--
Bug #44899 (__isset usage changes behavior of empty()) - 2
--FILE--
<?php

class myclass
{
	private $_data = array();

	function __construct($data)
	{
		$this->_data = $data;
	}

	function __isset($field_name)
	{
		return isset($this->_data[$field_name]);
	}
	
	function __get($var) {
		var_dump(empty($this->_data[$var]));
		return $this->_data[$var];
	}
}

$arr = array('foo' => '');

$myclass = new myclass($arr) ;

echo (isset($myclass->foo)) ? 'isset' : 'not isset';
echo "\n";
echo (empty($myclass->foo)) ? 'empty' : 'not empty';
echo "\n";
echo ($myclass->foo) ? 'not empty' : 'empty';
echo "\n";

?>
--EXPECT--
isset
bool(true)
empty
bool(true)
empty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.