Hi All,

Trying to get started using PEAR but having problems:

i.e. When trying to use DB in a script:

require_once('DB.php');

I get this error:

Fatal error: Undefined class name 'pear' in /usr/lib/php/DB.php on line 540

That would tell me that DB is being found, but a dependency for DB (ostensibly PEAR) is not.

So I go to command line and type:

pear package-dependencies DB

and get:

Cannot open 'DB' for parsing

I don't know exactly what that means but it doesn't sound good. (I tried running the same command as sudo).

But when I do:

pear list

everything seems peachy:

Installed packages, channel pear.php.net:

Package Version State
Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
DB 1.7.6 stable
DB_Pager 0.7 stable
DB_Table 1.2.1 stable
Date 1.4.6 stable
HTML_Common 1.2.2 stable
HTML_QuickForm 3.2.5 stable
HTML_Template_IT 1.1.3 stable
HTTP 1.4.0 stable
Mail 1.1.9 stable
Net_SMTP 1.2.8 stable
Net_Socket 1.0.6 stable
Net_UserAgent_Detect 2.1.0 stable
PEAR 1.4.7 stable
PHPUnit 1.3.2 stable
Pager 2.3.6 stable
XML_Parser 1.2.7 stable
XML_RPC 1.4.5 stable

and no problems installing new modules either. It's just that when I try to run DB in a script, it can't seem to "find" the base PEAR class?

So then just for kicks I add a second include, so it's like this:

require_once('PEAR.php');
require_once('DB.php');

which gives me this error:

Fatal error: Class db_error: Cannot inherit from undefined class pear_error in /usr/lib/php/DB.php on line 868

So now it's got the pear module but not the pear_error class?

Any ideas? Thanks in advance.

    can you please provide us with code for db.php and also a output of your php info file?

      rbblue8 --

      Thanks for your reply. :-)

      Entire DB class and PHP info are too long to post here.

      But it might help to know that DB is the latest stable release 1.4.7.

      The lines in question:

      Around line 540:

        if (!class_exists($classname)) {
                  $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
                                          "Unable to include the DB/{$type}.php"
                                          . " file for '$dsn'",
                                          'DB_Error', true);
                  return $tmp;
              }
      

      and around line 868 is where DB tries to extend the PEAR class:

      class DB_Error extends PEAR_Error

      So I'm pretty sure the problem is not with the code but with my installation or use of PEAR.

      Clearly, DB is looking for the PEAR class here, but as mentioned, when trying to explicitly include PEAR.php (which I'm not even sure I'm supposed to do) I still get the error:

      Fatal error: Class db_error: Cannot inherit from undefined class pear_error in /usr/lib/php/DB.php on line 868

      What lines from php info would be pertinent, so I can post just that?

      Thanks again!

        Hi All,

        Problem solved -- while testing, I had named the file 'pear.php' which was a namespace conflict with the pear.php module pear was trying to load. Just dumb.

        Thanks anyhow!

          Write a Reply...