为了兼容 php 7.2,我需要将以下 create_function() 重构为匿名函数:
function bbpp_thankmelater_shortcode_h($atts, $content = NULL) {
extract(Bbpp_ThankMeLater_Shortcoder::atts(array(
"email_type" => NULL,
"comment" => NULL,
"level" => 1
), $atts));
if ($email_type == "text") {
return str_repeat("*", $level) . " " . $content;
}
return "<h{$level}>" . $content . "</h{$level}>";
}
for ($i = 1; $i <= 6; $i++) {
Bbpp_ThankMeLater_Shortcoder::add("h{$i}", create_function("\$atts,\$content", "\$atts[\"level\"]={$i};return bbpp_thankmelater_shortcode_h(\$atts, \$content);"));
}
当使用Rector自动执行此操作时,我收到此错误:
[ERROR] Could not process "shortcodes/h.php" file, due to:
"Syntax error, unexpected T_NS_SEPARATOR, expecting ']':1".
任何想法?提前谢谢您的帮助