ID: 36675
Updated by: [EMAIL PROTECTED]
Reported By: iain at iaindooley dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: FreeBSD 6.0
PHP Version: 5.1.3RC3-dev
New Comment:
Comparing objects or resources to strings, booleans and integers is
obviously senseless.
This is expected behaviour.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2006-03-10 06:20:24] iain at iaindooley dot com
Description:
------------
object cannot be used in a boolean logic comparison.
Reproduce code:
---------------
$view here is of the class RsmlView:
if($view = $this->getView($view_name))
{
if($view!='DO NOT DISPLAY')
$view->display($this);
}
Expected result:
----------------
nothing special, just a boolean result
Actual result:
--------------
this code produces the notice:
Notice: Object of class RsmlView could not be converted to int
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36675&edit=1