|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-07 09:42 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 12:00:01 2025 UTC |
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