为了账号安全,请及时绑定邮箱和手机立即绑定

PHP 7.4 中包含/流过滤器发生了什么

PHP 7.4 中包含/流过滤器发生了什么

PHP
宝慕林4294392 2021-11-19 16:41:23
走!AOP 框架使用带有 include 语句的流过滤器来执行代理生成。它在 PHP 7.3 中运行良好,但现在在 PHP 7.4 beta 2 发布后,它看起来有些变化。不幸的是,流过滤器的文档很差,所以我无法检查发生了什么。也许有经验的人会知道。检查以下示例代码:// index.phpinclude __DIR__ . '/SampleFilter.php';SampleFilter::register();$uri = 'php://filter/read=sample.filter/resource='. __DIR__ . '/Sample.php';$content = file_get_contents($uri);include $uri;Sample::printIt();// SampleFilter.phpclass SampleFilter extends php_user_filter{    public const PHP_FILTER_READ = 'php://filter/read=';    public const FILTER_IDENTIFIER = 'sample.filter';    protected $data = '';    protected static $filterId;    public static function register(string $filterId = self::FILTER_IDENTIFIER) : void    {        if (!empty(self::$filterId))         {            throw new RuntimeException('Stream filter already registered');        }        $result = stream_filter_register($filterId, __CLASS__);        if ($result === false)        {            throw new Exception('Stream filter was not registered');        }        self::$filterId = $filterId;    }    public static function getId() : string    {        if (empty(self::$filterId))        {            throw new Exception('Stream filter was not registered');        }        return self::$filterId;    }    public function filter($in, $out, &$consumed, $closing)    {        while ($bucket = stream_bucket_make_writeable($in))        {            $this->data .= $bucket->data;        }如您所见,$content 已正确修改代码(完整)。但是在包含该文件时,它看起来像代码被分割为原始文件长度。PHP 打印错误:Parse error: syntax error, unexpected end of file in /(...)/Sample.php on line 9第 9 行是超出原始文件大小的地方。
查看完整描述

1 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

这是一个错误,在 PHP7.4 中引入。它已经在最新版本中修复了。


查看完整回答
反对 回复 2021-11-19
  • 1 回答
  • 0 关注
  • 153 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信