RE: [PHP-DEV] nameof feature
| From: | Alexandr Marchenko | Date: | Tue, 12 May 2015 16:08:16 +0000 |
| Subject: | RE: [PHP-DEV] nameof feature | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86170@lists.php.net to get a copy of this message | ||
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 <https://github.com/ggreer/the_silver_searcher>
--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