Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66248 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12759 invoked from network); 26 Feb 2013 16:28:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2013 16:28:41 -0000 Authentication-Results: pb1.pair.com header.from=pencap@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pencap@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.175 as permitted sender) X-PHP-List-Original-Sender: pencap@gmail.com X-Host-Fingerprint: 209.85.210.175 mail-ia0-f175.google.com Received: from [209.85.210.175] ([209.85.210.175:60895] helo=mail-ia0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/54-16132-9B2EC215 for ; Tue, 26 Feb 2013 11:28:41 -0500 Received: by mail-ia0-f175.google.com with SMTP id r4so3565187iaj.20 for ; Tue, 26 Feb 2013 08:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=YMV1+IGaCVartm9YxterWe+dv3uUcTlSGiaPpaeZhBc=; b=tIl9APOuydaN6wvjQVwfSKmR4c/8Xz15d6E/5u9WHGMKTStPIyp8a1B7/Ntodty8v5 hlu4CIsGr13B/O/YAcIXtCm/sf1Lzl3YeEbmRueDcMuq/wxnHLW4M76oW3K1xL0plFXG SGjYwt1o1k8KH1pjSofzeh53jM22FuKfQMSCtutxaM+h3HZpSewEIhz0b1N7OF8fQUCH ADENZ6wiBQwUss3zuE5smF+zo4MGAluD4APrJPuUsi+HEXXXJs1oyp0K47TCyrCnIv+L Hd0WygannMZTEGwi0NoS/knk3P4olzmDhSRsoB4BGPLio2TOGtK6BJqgqS/WJ5WOHy3Y Dw5A== MIME-Version: 1.0 X-Received: by 10.50.16.129 with SMTP id g1mr5358920igd.103.1361896118684; Tue, 26 Feb 2013 08:28:38 -0800 (PST) Received: by 10.50.85.232 with HTTP; Tue, 26 Feb 2013 08:28:38 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Feb 2013 08:28:38 -0800 Message-ID: To: Sara Golemon Cc: Nikita Popov , PHP Internals Content-Type: multipart/alternative; boundary=f46d044403ae6061c704d6a326e4 Subject: Re: [PHP-DEV] Add get_object_constants and get_class_constants From: pencap@gmail.com (Mike Willbanks) --f46d044403ae6061c704d6a326e4 Content-Type: text/plain; charset=UTF-8 > >> Before drafting an RFC I would like to gauge interest in adding: > >> get_object_constants and get_class_constants > >> > >> I have already drafted up a PR with the changes and supplemental data: > >> https://github.com/php/php-src/pull/292 > >> > You took the time to make a PR, but not an RFC? This should really be > the other way around (if at all). > Yeah, part of it is that I want to learn the internals so if I have to throw it away; I don't care too much about it. Would be different if I knew the internals far better than I do then I would likely start on that path. But I wanted to be able to see what the performance differences were, how to achieve it as I don't want to be one of those... yeah PHP should do this but I can't do the work... so I figure I'd start by writing it and finding help along the way until I can figure it out. :) > > > >> Currently this can only be done through ReflectionClass which is far > slower > >> than retrieving them directly from the constants table. Some simple > >> timings show that through reflection retrieving these values is 2-3 > times > >> slower than providing a quick access function for retrieval. > >> > > I don't quite see why we need this. The only argument seems to be > > performance and I'm not quite sure why performance would be relevant > here. > > At least I can't imagine in what kind of code fetching the class > constants > > is a bottleneck. > > > I'm meh on the perf issue. Yeah it's probably there, but it's buried > in the noise and I'm not so sure about use-cases. Not against it for > its own sake though. > Many open source projects frown on the usage of Reflection and ReflectionClass inside of the code base; this is part of the reason. Sure I could certainly use ReflectionClass and leverage that instead. The perception is that Reflection* is slow and as such by most maintainers it is advised to stay away from it unless you're caching the results. As stated the performance is not necessarily a _huge_ case here; however, the more places that this becomes incorporated in a code base the slower things get overall. Here is a simple use case of usage where MyClass2 can add in new constants without having issue: MyClass { const SUCCESS = 1; const FAILURE = -1; const FAILURE_UNCATEGORIZED = -2; public function __construct($code) { $code = (int) $code; if (!in_array($code, get_object_constants($this))) { $code = self::FAILURE; } } } MyClass2 extends MyClass { const FAILURE_MYTYPE = -3; } > > >> This also fits nicely amongst the current stack of: > >> get_object_vars, get_class_vars and get_class_methods > >> > > > Yay! Consistency! Boo! Poorly named get_*() methods should have been > called something else from the get-go, but it's too late for that. > Honestly, this is the bit that bugs me most. > Yeah; I just attempt to follow whatever is consistent in whichever area it is. I guess I am also curious here (not to divert from the thread) but if we do not want to add in more of these; why don't we deprecate the usage of the current get_class_vars, get_object_vars, get_class_methods, etc and attempt to have everyone move over to the Reflection use case? Obviously this would have to be in a major version but if as a language PHP is moving things to the reflection use cases then provide it only there? Seriously not attempting to open up a can of worms here; there has already been several threads on BC and deprecation in the last month or so overall on the ML. > > >> These functions are commonly asked about on areas such as StackOverflow > ( > >> > >> > http://stackoverflow.com/questions/956401/can-i-get-consts-defined-on-a-php-class > >> ) > >> amongst other places on the net. > >> > > > I... kinda don't care about this part of the argument. It's called > "Google", and if they can't find it in Reflection, they won't find it > here. > That is semi true; I believe most people would locate get_object_vars/get_class_vars and then are confused when they cannot get the constants. Still it is easy to locate the reflection so this argument is easily dropped. - Mike --f46d044403ae6061c704d6a326e4--