#37007 [Opn->Bgs]: __tostring failure

From: Date: Fri, 07 Apr 2006 09:42:52 +0000
Subject: #37007 [Opn->Bgs]: __tostring failure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-95425@lists.php.net to get a copy of this message
 ID:               37007
 Updated by:       derick@php.net
 Reported By:      spinalex_555 at hotmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Compile Failure
 Operating System: Win xp sp2
 PHP Version:      5.1.2
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

.


Previous Comments:
------------------------------------------------------------------------

[2006-04-07 09:36:52] spinalex_555 at hotmail dot com

Description:
------------
Using the magic function __tostring the result is an object and not a
string.

Reproduce code:
---------------
class DataBaseConnector{

	protected $connection;
	private $host, $user, $pw, $db,$state = "unconnected";

	
	public function __construct($connection_data){
		$this->host = $connection_data[host];
		$this->user = $connection_data[user];
		$this->pw = $connection_data[pw];
		$this->db = $connection_data[db];
		if ($this->connect()) {
			$this->state = "connected";
		}
	}
	
	private function connect(){
		$this->connection = mysql_connect($this->host, $this->user,
$this->pw);
		if (!$this->connection) return false;
		if (!mysql_select_db($this->db, $this->connection)) return false;
		return true;
	}
	...
	public function __tostring(){
		return $this->state;
	}
}


Expected result:
----------------
a string with "connected" or "unconnected"

Actual result:
--------------
new $x = DataBaseConnector(my_data)

echo $x; //it seems to be a string like "connected" or so
but
echo $x."<br>; //it returns Object id#1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37007&edit=1


Thread (2 messages)

« previous php.bugs (#95425) next »