file_get_contents函数

今天迁移一个SDK项目到新的机子上,发现项目无法跑起来,报500错误,通过分析,发现原来是file_get_contents函数再作怪,代码如下

 1 public function __construct($fileName) {
 2     // 载入文件
 3     $str = file_get_contents($this->fileName, false, null, -1, 2048);
 4     if (empty($str)) {
 5         throw new Exception\RuntimeException(sprintf(
 6                 'read %s error', $this->fileName
 7         ));
 8     return;
 9     }

参考官方介绍,file_get_contents函数的offset在7.1.0版本已经支持负数(下图)

对比本地的PHP版本,发现是7.1.11

虽然只差了一个小版本,但offset设为-1无法获取到对应内容,而将-1改为0以后,可正常获取

再次对比项目原来所在机子的PHP版本是7.0,却支持offset设为-1的操作,实在是没搞明白是怎么回事,不知道哪位大牛能告知一下~

http://www.php.net/manual/en/function.file-get-contents.php

猜你喜欢

转载自www.cnblogs.com/jshp/p/10137159.html