bundled-libs/PEAR.php issue

Discussion corner for Developers of Serendipity.
Post Reply
assent
Regular
Posts: 9
Joined: Thu Oct 18, 2007 12:20 pm

bundled-libs/PEAR.php issue

Post by assent »

Hi,

we've been experiencing a strange problem with PEAR's error constants not being defined. The actual place where this happens is the podcast event plugin (serendipity_event_podcast). It's not a plugin issue, its something that I think affects every code that uses the bundled PEAR libs (HTTP/Request,Net/Socket etc.)

Inside bundled-libs/PEAR.php there is a:

Code: Select all

if ( class_exists('PEAR') ) {
        return false;
}
This actually prevent the initialization of the constants and other GLOBALS[] data, as the class gets actually defined (compiled), but the statements do not run at all.

You can test for yourself with something like:

Code: Select all

<?php
require_once 'bundled-libs/PEAR.php';

echo "pear const: " . PEAR_ERROR_RETURN . " <<\n";
var_dump($GLOBALS); // make sure to grep for '^_PEAR'
?>
If the condition around class_exists() is removed, the constants and GLOBALS are initialized properly.

The effect of this, is that module don't actually control the PEAR error reporting mechanisms, unless they redefine those constants, which may or may not be an actual issue.

I guess a workaround inside PEAR.php would be using the trick like in other places around the source:
# PEAR.php
if ( defined('S9Y_PEAR') ) return false;

define ('S9Y_PEAR', 1);

here's my OS info:

6.2-STABLE FreeBSD 6.2-STABLE #1
PHP 4.4.7 with Suhosin-Patch 0.9.6 (cli) (built: Jul 30 2007 21:40:22)
Zend Engine v1.3.0
Apache/1.3.37 (Unix)


EDIT:
the s9y version is the latest official release - 1.2
----------------------------------------------------
Assen Tchorbadjiev
Aplus.Net Internet Services
assent [at] aplus.net
2C35 8891 6DCB 2D4C BAA0 13E9 35F9 7F6A 41E0 8A1E <pgp.mit.edu>
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: bundled-libs/PEAR.php issue

Post by garvinhicking »

Hi!

I see your point. It's REALLY strange, because I wonder how PEAR plugins then actually have worked in the past. %-)

I've changed the PEAR.php file by us to use a different detection routine, now it seems to work properly. Committed to both our SVN trunk and the 1.2 maintenance branch.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
assent
Regular
Posts: 9
Joined: Thu Oct 18, 2007 12:20 pm

Re: bundled-libs/PEAR.php issue

Post by assent »

garvinhicking wrote: [..]
I see your point. It's REALLY strange, because I wonder how PEAR plugins then actually have worked in the past. %-)
[..]
Well, they seem to work pretty well, unless someone actually tries to either manage the severity levels (either global or per-object), or there is a PEAR error.

In our case, we caught it when Net/Socket.php died due to being unable to connect to a certain host, but at the same time the default and run-time severity level was PEAR_ERROR_RETURN (ie, void).
The constants being uninitialized made the code (PEAR_Error) do the following:

Code: Select all

// $mode points to one of the constants
if ( $this->mode & PEAR_ERROR_XXX ) 
.. with both sides being strings, and the expression comes out as true.
----------------------------------------------------
Assen Tchorbadjiev
Aplus.Net Internet Services
assent [at] aplus.net
2C35 8891 6DCB 2D4C BAA0 13E9 35F9 7F6A 41E0 8A1E <pgp.mit.edu>
Post Reply