PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Authentication » LiveUser » Bug #214

Constructor returns error object on error. This isn't legal php code.

Details

Submitted2003-11-07 16:30 UTC
Frommfriedman at symcor dot com
Assignedmw21st
StatusClosed
PackageLiveUser
PHP Version4.3.3
OSLinux
Roadmaps(Not assigned)

Comments

[2003-11-07 16:30 UTC] mfriedman at symcor dot com

Description:
------------
In some versions of php you may return an object from the constructor that is not the same type as the constructor would normally return. In the constructor: "LiveUser_Admin_Auth_Container_DB", there is an error condition which results in a PEAR_Error object being return from the constructor. This is illegal php code and is not guaranteed to work in all versions of php. To address this, there should be a factory operation to instantiate this class (and any others that have this behavior) so that the factory operation can return the error if indeed there is one. This would "keep failing code out of the constructor".

See: http://bugs.php.net/bug.php?id=21380
This behavior will not be supported in ZE2.

Reproduce code:
---------------
The offending code is:
if ($conf['type'] != 'DB') {
return PEAR::raiseError('the configuration array does not match
this container type. Please use an array for a DB container.');

Here is the constructor:

function &LiveUser_Admin_Auth_Container_DB(&$connectOptions, $conf)
{
if (is_object($connectOptions)) {
$this->dbc = &$connectOptions;
$this->init_ok = true;
} elseif (is_array($connectOptions)) {
foreach ($connectOptions as $key => $value) {
if (isset($this->$key)) {
$this->$key = $value;
}
}

$this->dbc = DB::connect($connectOptions['dsn']);

if (!DB::isError($this->dbc)) {
$this->init_ok = true;
}
}

if ($conf['type'] != 'DB') {
return PEAR::raiseError('the configuration array does not match
this container type. Please use an array for a DB container.');
}

$this->authTableCols = array_merge($conf['authTableCols'], $this->authTableCols);
$this->authTable = $conf['authTable'];
} // end func LiveUser_Admin_Auth_DB

Expected result:
----------------
The expected result should be to return a valid object of type:
LiveUser_Admin_Auth_Container_DB

The constructor may or may not return this result depending on the version of php.

[2003-11-10 19:13 UTC] mw21st at php dot net

Will fix this.

[2003-11-11 20:31 UTC] mw21st at php dot net

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.

Actually, I made up my mind and won't fix it, as Lukas already did that in CVS, pick file version 1.21 or newer.

Thanks for the bug report anyway :-)