Something I noticed about $__Auth_OpenID_PEAR_AVAILABLE;

Markus Lanthaler markus at silverstripe.com
Mon Aug 13 01:13:55 PDT 2007


> If DB is installed, but you use a descendent of
> Auth_OpenID_DatabaseConnection, say for MDB2 wrapper (if it was even
> necessary?  Did I just do work for nothing?)  This still returns a
> value, causing setfetchmode to throw an error later.

Hi,

I found another situation where this causes a problem and submitted already 
a patch (hope it will be applied soon!):


----- Original Message ----- 
From: "Markus Lanthaler" <markus at silverstripe.com>
To: "discuss OpenID libraries and development" <dev at lists.openidenabled.com>
Sent: Tuesday, August 07, 2007 12:18 PM
Subject: Patch: Conflict when PEAR and a user created class DB is available


>I found a conflict and made a little patch for it. SQLStore.php tries to
> include DB.php to check if PEAR is available.
> When there is loaded already a class "DB" (which happens quite often), but
> also PEAR is available you'll get the following error:
>
> Fatal error: Cannot redeclare class DB in ...
>
> I created two simple patches since I didn't know which one is the better
> one. I prefer the second one because it eliminates the gloabal variable 
> and
> doesn't require that the user specifies a constant, but feel free to 
> choose
> one of the two:
>
> The first one introduces a new constant Auth_OpenID_PEAR_AVAILABLE which 
> can
> be set to FALSE to solve the problem:
>
> {
> hunk ./Auth/OpenID/SQLStore.php 24
> -$__Auth_OpenID_PEAR_AVAILABLE = @include_once 'DB.php';
> +if(defined('Auth_OpenID_PEAR_AVAILABLE') && !Auth_OpenID_PEAR_AVAILABLE) 
> {
> +    $__Auth_OpenID_PEAR_AVAILABLE = false;
> +} else {
> +    $__Auth_OpenID_PEAR_AVAILABLE = @include_once 'DB.php';
> +}
> +
> }
>
>
> The second one checks if a class DB is already declared and doesn't 
> include
> DB.php if so. Then it tries to set the fetch mode only if the relevant
> constant is set:
>
> {
> hunk ./Auth/OpenID/SQLStore.php 23
> -global $__Auth_OpenID_PEAR_AVAILABLE;
> -$__Auth_OpenID_PEAR_AVAILABLE = @include_once 'DB.php';
> +if((version_compare(phpversion(), "5.0.0", "<") && !class_exists('DB')) 
> ||
> +   (version_compare(phpversion(), "5.0.0", ">=") &&
> +    !class_exists('DB', false))) {
> +    // The class DB doesn't exists yet, try to include it
> +    @include_once 'DB.php';
> +}
> +
> hunk ./Auth/OpenID/SQLStore.php 91
> -        global $__Auth_OpenID_PEAR_AVAILABLE;
> -
> hunk ./Auth/OpenID/SQLStore.php 113
> -        if ($__Auth_OpenID_PEAR_AVAILABLE) {
> -            $this->connection->setFetchMode(DB_FETCHMODE_ASSOC);
> +        if (defined('DB_FETCHMODE_ASSOC')) {
> +            @$this->connection->setFetchMode(DB_FETCHMODE_ASSOC);
> }
>
>
>
> Markus Lanthaler
> 




More information about the Dev mailing list