FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=19058&edit=1

ID: 19058
Updated by: daniel.oconnor@gmail.com
Reported By: jdeyrieux at yahoo dot fr
Summary: spl_autoload_register() and PEAR::isError
-Status: Open
+Status: Duplicate
Type: Bug
Package: MDB2
Operating System: winxp sp3
Package Version: 2.5.0b3
PHP Version: 5.3.8
Roadmap Versions:
New Comment:

-Status: Open
+Status: Duplicate
Bug #18826


Previous Comments:
------------------------------------------------------------------------

[2011-11-19 17:26:22] jack331

Description:
------------
Hi,

When i use spl_autoload_register(), when i use
$mdb2->quote('hello','text');

the MDB2::isError function use function is_a($data) and trigger a call
to spl_autoload_register() with string value as classname ;-)

below code for check

Test script:
---------------
class c_autoloader {

public function __construct() {
spl_autoload_register(array($this, 'loader'));
}

private function loader($className) {
echo 'Trying to load ', $className, ' via ', __METHOD__, "()<br
/>\n";
$a = debug_backtrace(false);
print_r($a);
include($className . '.php');
}
}

$autoloader = new c_autoloader();

function dbConnect($dsn) {

$options = array(
'debug' => 2,
'result_buffering' => false,
);

$mdb2 =& MDB2::connect($dsn, $options);
if (PEAR::isError($mdb2)) {
die('connexion:'.$mdb2->getMessage());
}

$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
return $mdb2;
}
$mdb2 = dbConnect('your dsn');

$username = 'myusername';
$sql = 'SELECT * FROM users WHERE username='.$mdb2->quote($username);
$stmt = $mdb2->query($sql);


Expected result:
----------------
in fact, to block this, it's really easy with if check in replacement of
original. gettype($data)=='object' check if this var is an object

function isError($data, $code = null)
{
if (!gettype($data)=='object' || !is_a($data, 'PEAR_Error')) {
return false;
}



Actual result:
--------------
Array
(
[0] => Array
(
[function] => loader
[class] => c_autoloader
[type] => ->
[args] => Array
(
[0] => jdeyrieux
)

)

[1] => Array
(
[function] => spl_autoload_call
[args] => Array
(
[0] => jdeyrieux
)

)

[2] => Array
(
[file] => I:\Travail\home\pear\PEAR.php
[line] => 252
[function] => is_a
[args] => Array
(
[0] => jdeyrieux
[1] => PEAR_Error
)

)

[3] => Array
(
[file] =>
I:\Travail\home\pear\MDB2\Driver\Datatype\Common.php
[line] => 1230
[function] => isError
[class] => PEAR
[type] => ->
[args] => Array
(
[0] => jdeyrieux
)

)

[4] => Array
(
[file] =>
I:\Travail\home\pear\MDB2\Driver\Datatype\Common.php
[line] => 1176
[function] => _quoteText
[class] => MDB2_Driver_Datatype_Common
[type] => ->
[args] => Array
(
[0] => jdeyrieux
[1] => 1
[2] =>
)

)

[5] => Array
(
[file] => I:\Travail\home\pear\MDB2.php
[line] => 3056
[function] => quote
[class] => MDB2_Driver_Datatype_Common
[type] => ->
[args] => Array
(
[0] => jdeyrieux
[1] => text
[2] => 1
[3] =>
)

)

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedNov 21, '11 at 11:52a
activeNov 21, '11 at 11:52a
posts1
users1
websitepear.php.net

1 user in discussion

Daniel Oconnor: 1 post

People

Translate

site design / logo © 2022 Grokbase