Re: nameof feature
| From: | Bishop Bettini | Date: | Tue, 12 May 2015 14:58:24 +0000 |
| Subject: | Re: nameof feature | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86168@lists.php.net to get a copy of this message | ||
Hi!
On Tue, May 12, 2015 at 9:29 AM, Alexandr Marchenko <
marchenko.alexandr@gmail.com> wrote:
>
> Guys from C# implemented similar but more powerful feature: nameof(Acme),
> nameof(Acme.AnyMethod)
>
> https://msdn.microsoft.com/en-us/magazine/dn802602.aspx
>
> Imagine how much confidence it will give you while renaming your methods,
> class names etc.
>
Neat. So, how would that work in this scenario?
class God {
public static function create($method) {
call_user_func([ 'God', $method ]);
}
private static function chicken() {
echo 'Let there be chicken!';
}
}
God::create('chicken');
I understand nameof(God) would replace the literal string 'God', but how
would one replace the literal 'chicken' with the appropriate compile time
reference? Perhaps: nameof(God::chicken)
Also, since nameof() is a compile-time conversion
<http://tryroslyn.azurewebsites.net/#b:master/K4Zwlgdg5gBAygTxAFwKYFsDcAoADsAIwBswBjGUogQxBBgDEB7R7Ab2xk5n2LJgDdGYACYwAQlQBOAChSTIsXFKroAjAEoOXdl10wAwowghGRVADoA6vLQAZSKmkQVqRgDNpTRuvU49XQ2NTC2swOwcnF3dpCUkfP38DIxMzKxtUewhHZ3RXDyVJFQ1fLU4AX2wyoAA>,
nameof() wouldn't help a value construct like this:
God::create($_REQUEST['animal']);
So, overall, how does nameof(God) aid in refactoring more than a find and
subsequent replace, like ag <https://github.com/ggreer/the_silver_searcher>
--php "'God'"?
bishop