----- Original Message ----- From: "Daniel Schierbeck" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 20, 2004 10:47 AM
Subject: [PHP] Overloaded Class & The __tostring() Method
I am trying to build an XML-formatted string from an object. I use this code:
<?php
class XML_Object { private $childs = array();
public function __get ($prop) { if (isset($this->childs[$prop])) { return $this->childs[$prop]; } else { trigger_error("Property '$prop' not defined.", E_USER_WARNING); } }
public function __set ($prop, $val) { $this->childs[$prop] = $val; }
public function __tostring () { $re = "";
foreach ($this->childs as $key => $val) { $re .= "<$key>$val</$key>"; }
return $re; } }
$error = new XML_Object; $error->no = 2; $error->str = "Blablabla"; $error->file = "a_file.php"; $error->line = 54;
$xml = new XML_Object; $xml->error = $error;
echo $xml;
?>
But i only get this response:
<error>Object id #1</error>
Can someone help me? I want to print the contents of the $error object as well...
echo $xml->error->no; echo $xml->error->str; etc...
Not sure if that's exactly what you're after, though...
---John Holmes...
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php