note 123441 added to function.create-function
| From: | tomas dot vot at gmail dot com | Date: | Sun, 16 Dec 2018 01:17:28 +0000 |
| Subject: | note 123441 added to function.create-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209908@lists.php.net to get a copy of this message | ||
If you need to upgrade more than one
create_function to anonymous function, I'm
working on a tool that makes dev's life much easier and adaptable for new versions of anything
in PHP.
It's tested on 30+ various (and really weird :)) cases, like:
-$callback = create_function('$a', 'return
"<cas:proxy>$a</cas:proxy>";');
+$callback = function ($a) {
+ return "<cas:proxy>{$a}</cas:proxy>";
+};
Includes concat (.), string quotes and inclined function calls:
-$func = create_function('$atts, $content = null','return "<div
class=\"' . $class_list . '\">" . do_shortcode($content) .
"</div>";' );
+$func = function ($atts, $content = null) use ($class_list) {
+ return "<div class=\"{$class_list}\">" . do_shortcode($content) .
"</div>";
+};
Do you want to automate the hard work?
1. Instal Rector
composer require rector/rector --dev
2. Create config
# rector.yml
services:
Rector\Php\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector: ~
3. Upgrade your Code
vendor/bin/rector process src --config rector.yml --dry-run
vendor/bin/rector process src --config rector.yml
----
Server IP: 208.43.231.9
Probable Submitter: 94.112.220.185
----
Manual Page -- http://php.net/manual/en/function.create-function.php
Edit -- https://master.php.net/note/edit/123441
Del: integrated -- https://master.php.net/note/delete/123441/integrated
Del: useless -- https://master.php.net/note/delete/123441/useless
Del: bad code -- https://master.php.net/note/delete/123441/bad+code
Del: spam -- https://master.php.net/note/delete/123441/spam
Del: non-english -- https://master.php.net/note/delete/123441/non-english
Del: in docs -- https://master.php.net/note/delete/123441/in+docs
Del: other reasons-- https://master.php.net/note/delete/123441
Reject -- https://master.php.net/note/reject/123441
Search -- https://master.php.net/manage/user-notes.php