走!AOP 框架使用帶有 include 語句的流過濾器來執(zhí)行代理生成。它在 PHP 7.3 中運(yùn)行良好,但現(xiàn)在在 PHP 7.4 beta 2 發(fā)布后,它看起來有些變化。不幸的是,流過濾器的文檔很差,所以我無法檢查發(fā)生了什么。也許有經(jīng)驗(yàn)的人會知道。檢查以下示例代碼:// 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 已正確修改代碼(完整)。但是在包含該文件時(shí),它看起來像代碼被分割為原始文件長度。PHP 打印錯(cuò)誤:Parse error: syntax error, unexpected end of file in /(...)/Sample.php on line 9第 9 行是超出原始文件大小的地方。
PHP 7.4 中包含/流過濾器發(fā)生了什么
寶慕林4294392
2021-11-19 16:41:23