Here is example of how it works in C# 6:

http://video.ch9.ms/ch9/4419/cea3b3e4-715a-4279-b161-5962e4464419/VSToolboxCsharpVS2015withMadsTorgersen.mp4


time from 19:40 to 22:00


They demonstrate nameof on simple variable but it can be applied to anything, 
especially I’am thinking about callables where you have something like: [$this, 
‘doSomething’]





Sent from Windows Mail





From: mac
Sent: ‎Tuesday‎, ‎May‎ ‎12‎, ‎2015 ‎7‎:‎08‎ ‎PM
To: bis...@php.net
Cc: internals@lists.php.net








Hello Bishop,

 

For your first example I do not know what will be the best way but assume 
something like:

 

God::create(God::chicken);

 

In cases when you are giving strings to PHP (like in example with 
$_REQUEST[‘animal’]) all should work as is

 

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).

 

You are right – tools like ag --php "'God'" will do the work, but when it comes 
to rename method – there might be troubles, for example if I have code like:

 

class God { public function chicken() {} }

$data = $_REQUEST[‘chicken’];

calluser_func(God::class, ‘chicken’);

 

you cannot just rename word “chicken” in your code.

 

Also while you are typing God::chi| - you can get autocomplete, which will help 
you write less code and make less mistakes

Reply via email to