note 123441 deleted from function.create-function by cmb
| From: | cmb@php.net | Date: | Thu, 07 Jul 2022 14:46:00 +0000 |
| Subject: | note 123441 deleted from function.create-function by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218928@lists.php.net to get a copy of this message | ||
Note Submitter: tomas dot vot at gmail dot com
----
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