开发者

Deprecated errors when installing pear

I'm trying to install PEAR on OS X,开发者_JS百科 using the built-in PHP 5.3 installation. I did this:

curl http://pear.php.net/go-pear > go-pear.php
php go-pear.php

After answering some prompts, I start getting tons of errors like this:

Deprecated: Assigning the return value of new by reference is deprecated in /Users/username/bin/pear/temp/PEAR.php on line 563
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /Users/username/bin/pear/temp/PEAR.php on line 566

Now, I understand what these errors mean. I just want to hide them. So in my /private/etc/php.ini file, I have the following:

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

This hides those same errors in my own code. But in PEAR it doesn't. They seem to be changing the error_reporting level.

Is there a good way to fix this?


@kguest

I was unable to find the "php_ini" in config list.

@JW

I solved the problem by changing the behavior of PEAR command line's internal error handler: in file /usr/share/pear/pearcmd.php, at the bottom of the file, change the error_handler's body to :

if ($errno & error_reporting()) {
     $errortype = array (
        E_ERROR   =>  "Error",
        E_WARNING   =>  "Warning",
        E_PARSE   =>  "Parsing Error",
        E_NOTICE   =>  "Notice",
        E_CORE_ERROR  =>  "Core Error",
        E_CORE_WARNING  =>  "Core Warning",
        E_COMPILE_ERROR  =>  "Compile Error",
        E_COMPILE_WARNING =>  "Compile Warning",
        E_USER_ERROR =>  "User Error",
        E_USER_WARNING =>  "User Warning",
        E_USER_NOTICE =>  "User Notice"
    );
    $prefix = $errortype[$errno];
    global $_PEAR_PHPDIR;
    if (stristr($file, $_PEAR_PHPDIR)) {
        $file = substr($file, strlen($_PEAR_PHPDIR) + 1);
    } else {
        $file = basename($file);
    }
    print "\n$prefix: $errmsg in $file on line $line\n";
}

This will make PEAR command compatible with your php.ini error reporting level. (do the same with peclcmd.php)

By the way, this function used to read an empty config descriptor with

$GLOBALS['config']->get('verbose') < 4

So I tried to change the verbose level in PEAR config but it does nothing (yet this line raise a FATAL ERROR when reached).

I don't know what the PEAR maintainers had in mind when they created this component but they could at least provide a way to hide errors.


The problem is that PEAR is not compatible with PHP 5.3 and when you try to run it under PHP 5.3, it works but you get a lot of deprecation warnings.

To make things worse, the PEAR command line tool's behavior is that when PHP encounters errors, then regardless of the setting of "display_errors" INI setting, or even the "report_errors" setting, all errors are caught and displayed on standard output (and with extra empty lines to boot, so it will be extra annoying).

There are several ways to fix this, but they all involve editing pear's code directly on your machine. what eventually I did, is edit the 'pearcmd.php' file that PEAR installs, and change the print "..." command at the end (in the error_handler function) to file_put_contents("php://stderr","..."); (where ... stands for the correct text in the code). This causes all error messages to be output to the standard error stream instead of the standard output - as it should have been done in the first place, and then you can just add 2>/dev/null after your pear commands to silence the error messages if you don't want to see them.


It seems to me you need to change a pear config setting:

$pear config-set php_ini /private/etc/php.ini 

You can confirm this is set via

$pear config-get php_ini

or

$pear config-show


Unfortunately the maintainers of PEAR packages sometimes don't really care about these type of errors (I have encountered a similar problem, which was resolved as bogus). So I would not count on these errors being fixed anytime soon.

My solution is to set the error_reporting value in php.ini to only show real (fatal) errors, and to adjust this value in your own application. For the best behaviour, you should of course do this first. Something like this:

<?php
  // include required PEAR classes
  require_once('PEAR.php');

  class Application() {

      public static main() {
          // get $errlevel value from some sort of configuration
          error_reporting($errlevel);
      }

  }

  $myApp = Application::main();

?> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜