Re: Proposal for RFC: get_class_constants()

From: Date: Sun, 15 Dec 2013 23:15:17 +0000
Subject: Re: Proposal for RFC: get_class_constants()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70647@lists.php.net to get a copy of this message
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]

Thread (14 messages)

« previous php.internals (#70647) next »