|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-10 06:20 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 08:00:01 2025 UTC |
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;Yes, the line: if($this->top_reference == $ref) also causes the error, and changing the code in zend_operators.c as i posted fixed the problem. doing: $var = FALSE; if($some_other_var) $var = new SomeObject(); if($var) echo('we got here'); makes perfect sense, this is a bug.<?php class test { } $var = new test; var_dump($var == ""); var_dump($var == "non-empty"); ?> works perfectly fine.