Re: Solved: Curious problem overloading derived ObjectArray and __toString

From: Date: Fri, 27 Aug 2004 18:01:00 +0000
Subject: Re: Solved: Curious problem overloading derived ObjectArray and __toString
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-194950@lists.php.net to get a copy of this message
m'kay ... already got it. The routine was disabled due some internal problems. It should be reintroduced in PHP 5.1. *wait* http://www.rb21.com/news/index.php/m/115763/0/#msg_115763 Stefan wrote:
hi, I extended ArrayObject (SPL) to a new class. Let's call it ExtObjectArray. ExtArrayObject is quiet tiny, only with some simple functions. One is called getData() and serves some string data. Now I've overloaded the class using __toString() ...
    public function __toString() {
         return( $this->getData());
    }
What I wish to do is, to ... $obj = new ExtArrayObject; print( (string)$obj); ... and it doesn't work. And i've absolutly no idea why. PHP prints instead of the getData() String the object ID, as the __toString isn't called. What actually is true. There are no errors, no warnings, no notices at all. If i invoke __toString() [print( $obj->__toString())] direct, it works fine! First i assumed it's a spelling mistake. But __toString(), including the case, is okay (source: zend2-engine-changes). Then i tried it without access spec. So without public, but that doesn't work either. Replacing the return statement in the __toString() method with a simple print( "foo\n"), I realized, that the method won't be called. That really sucks! :o) My PHP Version is php 5.0.1 build from source. Btw.: this little example also doesn't work. --- begin <? class foo {
       function __toString() {
               return("hallo");
       }
} $a = new foo; echo (string)$a; ?> --- end Assigning to another var instead directly output the object doesn't work either as the Zend Changelog (till 2004-07-14) doesn't say anything explaining the problem. anybody have more clue about that? regards, Stefan


« previous php.general (#194950) next »