Yii2架構打包成Phar包報錯的經曆
以yii2為例
打包檔案過程比較簡單,但打包好以後,一直報錯:
PHP Fatal error: Uncaught yii\base\InvalidParamException: The directory does not exist: phar:///Users/jimmy/PHP/Library/yii2-advanced/yii2.phar/console in phar:///Users/jimmy/PHP/Library/yii2-advanced/yii2.phar/base/Module.php:224
一開始一直以為是打包出了問題有檔案沒有被打包進去,換了各種姿勢去打包,還是報各種錯。
最後沒辦法的情況下,去看了報錯的這個檔案,發現用了realpath來判斷路徑是否存在,注釋掉後,基本正常。這是php一個bug。
/** * Sets the root directory of the module. * This method can only be invoked at the beginning of the constructor. * @param string $path the root directory of the module. This can be either a directory name or a path alias. * @throws InvalidParamException if the directory does not exist. */public function setBasePath($path){ $path = Yii::getAlias($path); $p = $path;//realpath(); if ($p !== false && is_dir($p)) { $this->_basePath = $p; } else { throw new InvalidParamException("The directory does not exist: $path"); }}
http://git.oschina.net/web3d/codes/zyhsoev0b3i9u5njgaf42