走!AOP 框架使用带有 include 语句的流过滤器来执行代理生成。它在 PHP 7.3 中运行良好,但现在在 PHP 7.4 beta 2 发布后,它看起来有些变化。
不幸的是,流过滤器的文档很差,所以我无法检查发生了什么。也许有经验的人会知道。
检查以下示例代码:
// index.php
include __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.php
class 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 行是超出原始文件大小的地方。
MMMHUHU