#36675 [Bgs->Opn]: Cannot use an object with boolean expression
| From: | iain at iaindooley dot com | Date: | Fri, 07 Apr 2006 08:48:57 +0000 |
| Subject: | #36675 [Bgs->Opn]: Cannot use an object with boolean expression | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-95416@lists.php.net to get a copy of this message | ||
ID: 36675
User updated by: iain at iaindooley dot com
Reported By: iain at iaindooley dot com
-Status: Bogus
+Status: Open
Bug Type: Class/Object related
Operating System: FreeBSD 6.0
PHP Version: 5.1.3RC3-dev
New Comment:
haha i just notice that you (tony2001) were the one who stated:
Dmitry, I guess we need to return at least objects index in this
case.
Or maybe use the same way we use when compatibility_mode is on.
What do you think?
which is clearly what my patch does, which has somehow been undone in
later versions.
why would you dismiss such a thourough bug report as being senseless??
you could at least have the decency to forward it on to someone else.
Previous Comments:
------------------------------------------------------------------------
[2006-04-07 08:44:45] iain at iaindooley dot com
Wrong, this is not expected, as http://bugs.php.net/bug.php?id=33999
states, and this same notice is also caused by:
if($obj1 == $obj2)
please do not dismiss a bug without properly understanding what is
going on. if this is sensless then why doesn't it fail with the simple
test case i provided?
------------------------------------------------------------------------
[2006-04-07 08:37:04] tony2001@php.net
Comparing objects or resources to strings, booleans and integers is
obviously senseless.
This is expected behaviour.
------------------------------------------------------------------------
[2006-04-07 08:24:12] iain at iaindooley dot com
By the way, enabling compatbility mode causes problems because then you
cannot pass an object as the first argument of array_key_exists() which
is unintuitive
------------------------------------------------------------------------
[2006-04-07 07:29:17] iain at iaindooley dot com
It's back!! Sorry, I previously wrote that this problem seemed to have
disappeared when i updated to 5.1.3RC3-dev, but it is now back. The
error I'm getting is:
Notice: Object of class Clause could not be converted to int in
/usr/home/iain/public_html/vpc_test/packages/nozzle/db_object.class.php
on line 2151
the line that is causing it is:
if($this->unique_clause == '')
This does not happen consistently everytime an object is used in a
boolean expression and I am unable to create a simple test case that
replicates the bug. ie. if you execute the following with php -f
test.php:
<?
class ClassOne
{
private $var;
function ClassOne()
{
$this->var = 'some value';
}
}
$var = '';
if($var == '')
{
echo('there is nothing there
');
}
$var = new ClassOne();
if($var == '')
{
echo('there is still nothing there!
');
}
else
{
echo('houston, we have no problem
');
}
die('done testing
');
?>
then you get:
> php -f test.php
there is nothing there
houston, we have no problem
done testing
as expected. It's difficult to know where to go from here because this
is obviously a bug, because it is perfectly okay to use an object in a
boolean expression, and this behaviour is _not_ exhibited in PHP 5.0.4,
but I am unable to provide you with a simple test case that reproduces
the bug.
A similar problem occurred in http://bugs.php.net/bug.php?id=33999, and
it is supposedly fixed in CVS but it has apparently crept back in.
I have been able to hack in a fix for this in the code for 5.1.3RC3-dev
with the following patch, which apparently just bypasses something
called compatibility mode:
Index: zend_operators.c
===================================================================
RCS file: /repository/ZendEngine2/zend_operators.c,v
retrieving revision 1.208.2.4
diff -u -r1.208.2.4 zend_operators.c
--- zend_operators.c 5 Feb 2006 17:07:40 -0000 1.208.2.4
+++ zend_operators.c 7 Apr 2006 07:28:18 -0000
@@ -333,14 +333,15 @@
return;
}
- if (EG(ze1_compatibility_mode)) {
+ /*if (EG(ze1_compatibility_mode)) {*/
+ else {
HashTable *ht =
Z_OBJPROP_P(op);
if (ht) {
retval =
(zend_hash_num_elements(ht)?1:0);
}
- } else {
+ }/* else {
zend_error(E_NOTICE, "Object of
class %s could not be converted to int", Z_OBJCE_P(op)->name);
- }
+ }*/
zval_dtor(op);
ZVAL_LONG(op, retval);
return;
------------------------------------------------------------------------
[2006-04-06 05:25:30] iain at iaindooley dot com
I used CVS to checkout 5.1.3RC3-dev and the problem has miraculously
evaporated.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/36675
--
Edit this bug report at http://bugs.php.net/?id=36675&edit=1