On Tue, Jan 21, 2014, at 02:18 PM, Crypto Compress wrote:
> Hi,
>
> why not use __toString?
>
> class File {
> // "Resource(stream)" isn't all that useful
> private $fp;
>
> // But all the stream meta data is
> public function __toString() {
> return $this->fp ? print_r(stream_get_meta_data($this->fp),
> true) : ''; // var export, what ever you like
> }
>
> public function open($filename, $mode = 'r'){
> $this->fp = fopen($filename, $mode);
> }
> }
>
> $f = new File;
> echo $f; // object(File)#1 { }
> $f->open('http://php.net');
> echo $f;
>
> cryptocompress
Because the __toString allows a class to decide how to react when
treated like a string. Sure, that could be debug info, but it could be
printing a full-blow decorator implementation (e.g. Zend\Form\Form), a
number, class name, etc. What Sara is proposing is specific to object
debugging.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>