Re: [RFC] __debug_info()

From: Date: Tue, 21 Jan 2014 22:21:38 +0000
Subject: Re: [RFC] __debug_info()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-71392@lists.php.net to get a copy of this message
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 >

« previous php.internals (#71392) next »