#37007 [NEW]: __tostring failure
From: spinalex_555 at hotmail dot com
Operating system: Win xp sp2
PHP version: 5.1.2
PHP Bug Type: Compile Failure
Bug description: __tostring failure
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 bug report at http://bugs.php.net/?id=37007&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37007&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=37007&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37007&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37007&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37007&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37007&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37007&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37007&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37007&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37007&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37007&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37007&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37007&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37007&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37007&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37007&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37007&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37007&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37007&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37007&r=mysqlcfg
Thread (2 messages)
- spinalex_555 at hotmail dot com