Re: [RFC] Allow ::class on objects
| From: | Larry Garfield | Date: | Fri, 10 Jan 2020 17:29:09 +0000 |
| Subject: | Re: [RFC] Allow ::class on objects | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108091@lists.php.net to get a copy of this message | ||
On Thu, Jan 9, 2020, at 6:10 PM, Marcio Almada wrote:
> Em qui., 9 de jan. de 2020 às 20:57, Mike Schinkel
> <mike@newclarity.net> escreveu:
> >
> > > On Jan 9, 2020, at 6:53 PM, Marcio Almada <marcio.web2@gmail.com> wrote:
> > >
> > > Because we would be expanding a construct that already looks
> > > inappropriate from a purely
> > > semantic POV with aliases that also would allow inappropriate usage
> > >
some_function::interface.
> > > I'd rather have a generally unsatisfying construct than a set of
> > > "denormalized" constructs with
> > > equal potential for human inaccuracy.
> > >
> > > Perhaps the problem is that ::class was not exactly a
> > > good language
> > > design decision in the first place or maybe
> > > it made more sense in the past and as the language evolved it started
> > > to appear to be named poorly.
> > >
> > > A more _general_ construct like a nameof operator, as
> > > we have in C#,
> > > could have been a brighter idea. See:
> >
> > Okay, I get your perspective on this now.
> >
> > So let us add ::nameof and deprecate ::class, then? And apply it for all symbols? :-)
> >
> > -Mike
>
> It seems late to mess with ::class, maybe not for having
> nameof.
I've never been bothered by Interface::class or Trait::class, frankly. But having to remember
slightly different APIs for slightly different cases that I often have to handle together has caused
me no end of pain. -1 to needing to think about which type of bracketed reference thingie I am
getting a name for.
But having some kind of working way to reference a function that doesn't involve concatenating
a string onto a namespace constant would be *super* nice. Whether it's called ::func or
::nameof I don't much care.
Viz, replace this:
$func = __NAMESPACE__ . '\myfunc`';
With this:
use My\Code\myfunc;
$func = myfunc::nameof;
(Or basically anything that lets me not use strings to reference a function by name.)
To the OP suggestion of $object::class, I don't think I've run into a need for it but
since the name is already reserved I don't see a negative; I'm good with it.
--Larry Garfield