Hi,
following the howto for RFCs and since this would be my first one, I'd
like to ask for your thoughts if such an RFC might find approval. If
yes, I'll be happy to work on it.
Proposal: Create a function get_class_constants()
It would be similar to get_class_methods()
and get_class_vars()
.
Currently the same behavious is only possible by the help of reflection,
which due to the nature of reflection takes a bit more work/cpu-cycles.
$reflection = new \ReflectionClass($class);
$constants = $reflection->getConstants();
Kind regards,
Stefan
Hi!
I don’t know much about RFC’s yet - but I would totally vote for that. There are many use cases for that function, and it wouldn’t break anything BC related too.
Kind regards,
Ingwie
Am 14.12.2013 um 01:28 schrieb Stefan Neufeind neufeind@php.net:
Hi,
following the howto for RFCs and since this would be my first one, I'd
like to ask for your thoughts if such an RFC might find approval. If
yes, I'll be happy to work on it.Proposal: Create a function get_class_constants()
It would be similar to
get_class_methods()
andget_class_vars()
.Currently the same behavious is only possible by the help of reflection,
which due to the nature of reflection takes a bit more work/cpu-cycles.$reflection = new \ReflectionClass($class);
$constants = $reflection->getConstants();Kind regards,
Stefan
Currently the same behavious is only possible by the help of reflection,
which due to the nature of reflection takes a bit more work/cpu-cycles.
Unless you're doing this a billion times a second, I can't see why the
number of cpu cycles for this would matter. And why duplicate
functionality needlessly, in that case? What's so bad about the current
Reflection way of doing it, except for performance?
I can't see this proposal really being that useful or going anywhere.
--
Andrea Faulds
http://ajf.me/
Andrea Faulds wrote:
Currently the same behavious is only possible by the help of reflection,
which due to the nature of reflection takes a bit more work/cpu-cycles.Unless you're doing this a billion times a second, I can't see why the number of
cpu cycles for this would matter. And why duplicate functionality needlessly, in
that case? What's so bad about the current Reflection way of doing it, except
for performance?I can't see this proposal really being that useful or going anywhere.
If it is the only reason you are having to activate reflections? Reflections
would seem to have a place, but is it really necessary to add yet another layer
when most of the time it's function is provided better by IDE tools anyway? This
is a simple example of a current hole in the core PHP tools which would help a
section of developers who don't need the overheads of additional layers.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
If it is the only reason you are having to activate reflections?
Reflections would seem to have a place, but is it really necessary to add
yet another layer when most of the time it's function is provided better by
IDE tools anyway? This is a simple example of a current hole in the core
PHP tools which would help a section of developers who don't need the
overheads of additional layers.
@Lester additional layer is still better than yet another shortcut.
Since we already have the feature, introducing another flavor for it seems
a bit of an overkill, especially if it also has to be maintained.
Any userland implementation can handle this by also being fast enuff:
function get_class_constants($className)
{
static $cached = [];
if (isset($cached[$className])) {
return $cached[$className];
}
return $cached[$class] = (new \ReflectionClass($class))->getConstants();
}
Marco Pivetta
-----Original Message-----
From: Marco Pivetta [mailto:ocramius@gmail.com]
Sent: Saturday, December 14, 2013 2:51 PM
To: Lester Caine
Cc: PHP Internals List
Subject: Re: [PHP-DEV] Proposal for RFC: get_class_constants()If it is the only reason you are having to activate reflections?
Reflections would seem to have a place, but is it really necessary to add
yet another layer when most of the time it's function is provided better by
IDE tools anyway? This is a simple example of a current hole in the core
PHP tools which would help a section of developers who don't need the
overheads of additional layers.@Lester additional layer is still better than yet another shortcut.
Since we already have the feature, introducing another flavor for it seems
a bit of an overkill, especially if it also has to be maintained.Any userland implementation can handle this by also being fast enuff:
function get_class_constants($className)
{
static $cached = [];if (isset($cached[$className])) { return $cached[$className]; } return $cached[$class] = (new \ReflectionClass($class))->getConstants();
}
Marco Pivetta
I am asking myself why PHP hasn't implement ReflectionClass the way Stefan wants to implement get_class_constants() if his approach is faster.
I agree that it is somewhat an overkill to have another function for this but maybe Stefan can instead propose to change the implementation for ReflectionClass and all would benefit from it?
On the other hand, it's quite inconsistent to have get_class_methods()
, get_class_vars()
but not get_class_constants().
2013.12.14. 1:29, "Stefan Neufeind" neufeind@php.net ezt írta:
Hi,
following the howto for RFCs and since this would be my first one, I'd
like to ask for your thoughts if such an RFC might find approval. If
yes, I'll be happy to work on it.Proposal: Create a function get_class_constants()
It would be similar to
get_class_methods()
andget_class_vars()
.Currently the same behavious is only possible by the help of reflection,
which due to the nature of reflection takes a bit more work/cpu-cycles.$reflection = new \ReflectionClass($class);
$constants = $reflection->getConstants();Kind regards,
Stefan--
Please go for it!
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.
internals@lists.php.net/msg64242.html" rel="nofollow" target="_blank">http://www.mail-archive.com/internals@lists.php.net/msg64242.html
Cheers!
cryptocompress
Troll much?
Anyways, along the rest of the thread, a function to support the people
working with objects that don't want to work with objects is a weak place
to argue from. However if we're keeping get_class_* methods, API completion
seems worthwhile.
On Dec 15, 2013 3:13 PM, "Crypto Compress" cryptocompress@googlemail.com
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.internals@lists.php.net/msg64242.html" rel="nofollow" target="_blank">http://www.mail-archive.com/internals@lists.php.net/msg64242.html
Cheers!
cryptocompress
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.internals@lists.php.net/msg64242.html" rel="nofollow" target="_blank">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]
2013.12.14. 1:29, "Stefan Neufeind" neufeind@php.net ezt írta:
Proposal: Create a function get_class_constants()
Please go for it!
+1
--
Regards,
Mike
Hi Stefan
2013/12/14 Stefan Neufeind neufeind@php.net:
Hi,
Proposal: Create a function get_class_constants()
I cooked up a quick little patch, is this what you wanna have included
in the core?
Sorry it does not include any phpt's but the code is fairly easy to understand
--
regards,
Kalle Sommer Nielsen
kalle@php.net
Hi
2013/12/15 Kalle Sommer Nielsen kalle@php.net:
I cooked up a quick little patch, is this what you wanna have included
in the core?
For some reason the link must have been relocated, heres a new one:
http://pastie.org/8553749
--
regards,
Kalle Sommer Nielsen
kalle@php.net