Re: [RFC] Alternative typehinting syntax for accessors

From: Date: Thu, 10 Jan 2013 23:33:20 +0000
Subject: Re: [RFC] Alternative typehinting syntax for accessors
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Thu, Jan 10, 2013 at 11:11 PM, Stas Malyshev <[email protected]>wrote:

> Hi!
>
> The proposal is pretty clear, but could you explain this part:
>
> The current accessors proposal will need special handling of the
> typehint in any case (it can't be handled as a normal method typehint).
>
> What special handling is required?
>

I have written that in anticipation of a rewrite of the current automatic
accessor implementation. Currently it creates a string of PHP code and
compiles it as the method body. We were planning to replace this with
handling directly in the object handlers (because automatic accessors just
need to use the "normal" property code rather than the accessor one). In
this case we'd have to handle the typehint explicitly. But I'm not sure
whether we will still do this, so I'm not sure whether that statement in
the RFC is still true. On this subject, are you (personally) okay with the
current approach for creating automatic accessors (i.e. create PHP code
string and compile)?

> One question that still needs to be discussed is what syntax regarding
> > parentheses we want to use if this makes it. Currently both set { } and
> > set($foo) { } style accessors are supported. Do we want to keep those two
> > with the new syntax?
>
> Within this context, I'd prefer getting rid of set {} and only have
> set($param) {}. You don't save that much typing and you do it at the
> cost of additional obscurity and complexity - now every developer and
> every tool that deals with it needs to remember there's hidden $value
> parameter. IMHO not worth it. I can see what "get;" gives you - you can
> say "just do the natural thing". But if you start writing code anyway -
> i.e. if you do {} - then I think it should look like a real function.
>

Just to make sure I got it all right, you are suggesting:
 * Parentheses must be used on all accessors, so it's set($value) {} and
get() {} and isset() {} and unset() {} and something like get {} is not
possible?
 * Automatic accessors don't have parentheses so they are just set; get;
isset; unset;

Is that right? If so, then I think it's a reasonable approach.

Nikita


Thread (47 messages)

« previous php.internals (#64835) next »