Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6522 invoked from network); 15 Dec 2013 23:15:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Dec 2013 23:15:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.177 mail-we0-f177.google.com Received: from [74.125.82.177] ([74.125.82.177:59456] helo=mail-we0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/00-05839-3183EA25 for ; Sun, 15 Dec 2013 18:15:32 -0500 Received: by mail-we0-f177.google.com with SMTP id u56so3969909wes.36 for ; Sun, 15 Dec 2013 15:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=yosAW/hJxKVO23pA3fyYci/SIT3VEq2ovY+QQ+cF4QM=; b=dJTuVJBaaueVgTk/FkOi83Jf7fa/5tREwAYzzPHnphgfaTuJxvMIGQBhr+8V6DRECv 7E83hd5XMvUP93aCUZeo+WoxGi1SVRtvQexjhS1UtbhRmPYsSLb7mU1yuUZOH7huiGUl RS0b/KRf9EUwxN6vqAtbnh36HlM19v0+idY0Rsu3KYH5j7gYyXJU7qL/V70ZjQiq6ydX jarrxnMrD1OLqrIVhpSl/zNgIxKQH0d6ZD3h39W6AInFraV0bHN3LT03Bml5MGXJIz+c xw1Q+MiJXGYj4YfnRAdvbuPA4HdVBhyurI29avylsKUxhL+hj1Ns0FdcjGt/CKZJPsik xg6g== X-Received: by 10.180.108.83 with SMTP id hi19mr10799864wib.26.1387149328641; Sun, 15 Dec 2013 15:15:28 -0800 (PST) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id dn2sm20380449wid.1.2013.12.15.15.15.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 15 Dec 2013 15:15:27 -0800 (PST) Message-ID: <52AE3805.90209@gmail.com> Date: Sun, 15 Dec 2013 23:15:17 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <52ABA642.9090206@php.net> <52AE1B46.60406@googlemail.com> In-Reply-To: <52AE1B46.60406@googlemail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Proposal for RFC: get_class_constants() From: rowan.collins@gmail.com (Rowan Collins) On 15/12/2013 21:12, Crypto Compress wrote: > Hi, > > a short fairy tale: > For a long time thePHPway™ was to build a function for everything > someone needed/could imagine. This is why PHP is so easy, effective > and triumphant. But somehow the highlander principle found it's way > into PHP and nothing will ever be as it was before. So flog the > reflection argument to death. > > http://www.mail-archive.com/internals@lists.php.net/msg64242.html > > Cheers! > cryptocompress > Buried in the excessive snark of this message is a useful piece of information: the proposal has come up before, and an implementation was even provided, along with a few use cases which might benefit from the small performance improvement of having a direct implementation separate from the full ReflectionClass. It also reminded me of another use case: exceptions. Since the "code" of an Exception has to be an integer, writing a readable summary of an exception to a text-only log is tricky: if you just echo the code itself, you'd have to go back to the source code (or phpdoc) to look up its meaning. But when *constructing* an Exception, you will generally use a class constant to specify the code. If you grab all the class constants of the particular Exception sub-class, you can - hopefully - find the one with the appropriate value, and write its name to the log, rather than the number. That look-up may well happen every time you push an exception into the logging handler, so keeping it high-performance is probably a good idea. I suspect there are other slow points of such a function, but if constructing a ReflectionClass carries an inherent cost, it would be nice to avoid doing so. Regards, -- Rowan Collins [IMSoP]