【问题标题】:How to fix create_function when swapping to PHP 7.2 [duplicate]切换到 PHP 7.2 时如何修复 create_function [重复]
【发布时间】:2019-01-14 21:02:00
【问题描述】:

我看到有人帮助重写匿名函数。 但我真的不知道怎么做:

已弃用:函数 create_function() 在第 149 行的 /mnt/web110/c3/68/51799968/htdocs/portfolio2017/wp-content/themes/clean-photo-wp-modified/internal/includes.php 中已弃用

方法:

/**
 * Safe file inclusion
 *
 * @param $path
 */
public static function include_isolated( $path ) {
    if ( ! self::$include_isolated_callable ) {
        self::$include_isolated_callable = create_function( '$path', 'include $path;' );
    }

    call_user_func( self::$include_isolated_callable, $path );
}

【问题讨论】:

  • = function($path){include $path;};
  • 我想知道目的是什么。如果它是静态调用的,将其包装在另一个本地函数范围内并不会为包含的脚本隐藏更多内容。

标签: php php-7.2


【解决方案1】:
self::$include_isolated_callable = function($path) { include $path; };

http://php.net/manual/en/functions.anonymous.php

【讨论】:

  • 缺少分号,请链接到英文手册
  • 我做到了。谢谢!
  • 非常感谢。现在我又近了一步。最好的是我实际上明白你在那里做了什么:D
  • 不客气 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 2019-04-03
相关资源
最近更新 更多