tags:

views:

177

answers:

3

I'm trying to install PEAR on OS X, 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?

A: 

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
kguest
A: 

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();

?> 
Peter Kruithof
I overlooked something, if you think some PEAR class is changing the error_reporting value, please find out which one and post it here. I haven't encountered a package yet which does this.
Peter Kruithof
A: 

@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.

Ben