Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71444 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52900 invoked from network); 23 Jan 2014 16:13:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2014 16:13:10 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.241 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.241 imap3-1.ox.registrar-servers.com Received: from [198.187.29.241] ([198.187.29.241:58706] helo=imap3-1.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/52-39789-59F31E25 for ; Thu, 23 Jan 2014 11:13:10 -0500 Received: from localhost (localhost [127.0.0.1]) by oxmail.registrar-servers.com (Postfix) with ESMTP id A36A12A006A; Thu, 23 Jan 2014 11:13:06 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap3.ox.registrar-servers.com Received: from oxmail.registrar-servers.com ([127.0.0.1]) by localhost (imap3.ox.registrar-servers.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id b9-PKtvE2Sx9; Thu, 23 Jan 2014 11:13:06 -0500 (EST) Received: from [192.168.0.200] (unknown [176.25.177.94]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 9A6592A0053; Thu, 23 Jan 2014 11:13:05 -0500 (EST) Message-ID: <52E13F8F.2060700@ajf.me> Date: Thu, 23 Jan 2014 16:13:03 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Will Fitch , Crypto Compress , PHP Developers Mailing List References: <1390341389.11834.90.camel@guybrush> <52DEF226.6050500@googlemail.com> <1390342898.4170.73673993.2C28BAEC@webmail.messagingengine.com> In-Reply-To: <1390342898.4170.73673993.2C28BAEC@webmail.messagingengine.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] __debug_info() From: ajf@ajf.me (Andrea Faulds) On 21/01/14 22:21, Will Fitch wrote: > 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. Right. To see the difference better, I suggest looking at what Python does. It has a __string__() magic method and a __repr__() magic method, for string conversion and debug info, respectively. For a date, these result in: >>> x = datetime.datetime(1996, 02, 17) >>> x datetime.datetime(1996, 2, 17, 0, 0) >>> str(x) '1996-02-17 00:00:00' >>> repr(x) 'datetime.datetime(1996, 2, 17, 0, 0)' While the str() result is what you want for displaying that date, the repr() result shows you how it was constructed, which is more useful for debugging. For another example, see what Python strings do here: >>> n = "line 1\nline 2" >>> print n line 1 line 2 >>> print repr(n) 'line 1\nline 2' The first one's might not be very useful for debugging, because it outputs control characters raw. The debug output version, however, is much better for this. -- Andrea Faulds http://ajf.me/