【问题标题】:PHP_Beautifier - Fatal Error - require PEAR.phpPHP_Beautifier - 致命错误 - 需要 PEAR.php
【发布时间】:2021-04-01 19:11:53
【问题描述】:

我已经用 sudo 安装了 pear 和 php_beautifier...

根据我的阅读,我应该能够使用命令格式化代码

php_beautifier x.php

但是当我尝试这样做时,我得到了这个错误:

Warning: require_once(PEAR.php): failed to open stream: No such file or directory in /Users/philip/pear/bin/php_beautifier on line 37

Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:') in /Users/philip/pear/bin/php_beautifier on line 37

我查看了 php_beautifier.php 代码,但不知道有什么问题。第 37 行:

require_once 'PEAR.php';

并且该文件与 pear.php 位于同一目录中?

【问题讨论】:

  • @SalmanA 我的错,我的文件夹中有 pear 但没有 pear.php .. 只复制 pear 的一个版本并将其命名为 pear.php 在同一个文件夹中是否安全?跨度>
  • 也许你不必这样做。执行php -i > phpinfo.txt,打开文件并记下include_path 的值。如果它包含有效的/path/to/the/folder/that/contains/PEAR.php,那么问题就出在其他地方。否则你只需要在 php.ini 文件中添加/编辑路径。
  • @SalmanA - 我发现我需要的所有文件都在 .../pear/share/pear/ 我刚刚将它包含在 php.ini 中并且它有效:D 谢谢!

标签: php macos terminal pear php-beautifier


【解决方案1】:

理想情况下,PEAR 目录的路径应该在 php.ini 的include_path 指令中指定。这使您可以轻松地在代码中包含 PEAR 核心和包,例如:

require_once 'PEAR.php';
require_once 'Console/Getopt.php';

否则,您将不得不指定 PEAR 目录的完整路径,这会降低您的代码的可移植性:

require_once '/usr/share/pear/PEAR.php';
require_once '/usr/share/pear/Console/Getopt.php';

要探测include_path 指令的有效值,请使用phpinfo() 函数。如果它不包含 PEAR 安装路径,请使用:

# UNIX
include_path = ".:/path/to/pear"
# Windows
include_path = ".;C:\path\to\pear"

更详细和逐步的instructions can be found here

【讨论】:

    【解决方案2】:

    打开/private/etc/php.ini

    并替换这一行(796):

    ;include_path = ".:/php/includes"
    

    到:

    include_path = "/usr/lib/php/pear"
    

    【讨论】:

      【解决方案3】:

      先检查pear是否安装用命令:

      pear
      

      如果未安装,请使用此命令安装:

      sudo apt install php-pear
      

      【讨论】:

        猜你喜欢
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-27
        • 2016-07-06
        • 2013-07-23
        • 2015-02-13
        相关资源
        最近更新 更多