On 12 May 2015 17:08:16 BST, Alexandr Marchenko <marchenko.alexa...@gmail.com> wrote: >Idea of nameof (at least in my understanding) is to reduce string usage >and replace them with “strongly” typed “pointers” which can give us >feedback while script is processed (like when you misstyped method name >php will give you fatal error).
The validation part makes sense, but from the description linked, there are no pointers involved, it just results in an ordinary string. In many cases, the string is only needed in the first place because there isn't a way of getting a better pointer - e.g. when passing in a class name to a factory, or a method name to some dynamic call mechanism. It would seem like a better idea to tackle that underlying problem, with some mechanism for passing classes, methods, etc as first-class types. The example in that blog post of accessing a parameter name seems very ugly to me. If a function takes positional, not named, arguments, then why should any outside code *care* what name they're implemented under? There is no wrong answer to "what name should I mention in this error message?". With named parameters, that all changes, because names become part of the signature, not the implementation. My current feeling is that parameters should be named independent of the local variables they assign to, e.g. function foo($bar as x, $baz as y) { return $bar / $baz; } foo(y: 42, x: 420); // 10 In which case, you'd sometimes want some equivalent of nameof($bar) to give you 'x', which would be very messy. Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php