Welcome to WebmasterWorld Guest from 18.208.159.25

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Object could not be converted to int error

     
10:04 am on Feb 28, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 21, 2007
posts: 70
votes: 0


I just moved some code over from a PHP 5.2.4 server to a PHP 5.1.4 server and I'm getting the following error:

Notice: Object of class Account could not be converted to int in /account.class.php on line 246

Line 246, within the Account class definition, is the "if" statement here:


public function __destruct(){
if(!isset($_SESSION['account']) $_SESSION['account'] != $this) $_SESSION['account'] = $this;
}

Is there something different about the way 5.1.4 handles __destruct that might be causing this?

3:05 pm on Feb 28, 2008 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


Well, it looks like $_SESSION['account'] is storing an integer, probably the primary key of the DB record? So in the second comparison,
$_SESSION['account'] != $this
PHP has an integer on the left side and an object reference on the right side, so it tries to juggle [us2.php.net] that object into an integer.

What is the variable name in the class that stores the integer account number? Whatever it is, you should change the $this to $this->account.

5:14 pm on Feb 28, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 21, 2007
posts:70
votes: 0


Well, you were right about PHP trying to juggle that object into an integer. I added !is_object to my IF statement and that took care of it, keeping it from making it to the last comparison of object to object.

Any idea why 5.2.4 has no problem returning false to an object to int comparison whereas 5.1.4 fails on it? Was this considered a bug or is it something else in my configuration of 5.1.4 that's independent of the version?

Thanks for the help, btw.