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...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to