From: ob dot php at daevel dot fr
Operating system: Linux
PHP version: 5.2.6
PHP Bug Type: PDO related
Bug description: PDOStatement::fetchObject prototype error ?
Description:
------------
Hello,
the prototype of PDOStatement::fetchObject() say that the first parameter
($class_name) is required.
But you can call it without specifying this parameter, and without any
error.
So, witch is wrong ?
Reproduce code:
---------------
<?php
// With E_STRICT this produce an error because $class_name is set as
optional here.
class myPDOStatement extends PDOStatement
{
protected function __construct()
{
}
public function fetchObject( $class_name = NULL, $ctor_args = NULL )
{
return parent::fetchObject();
}
}
echo PHP_EOL;
// To verify the current prototype :
Reflection::export(new ReflectionMethod('PDOStatement', 'fetchObject'));
$db = new PDO('sqlite::memory:');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("create table test ( id integer not null )");
$db->exec("insert into test values ( 5 )");
// But as you can see, $class_name is not required
if( $res = $db->query( "select id from test" ) ){
while( $row = $res->fetchObject() ){
var_dump( $row );
}
}
Expected result:
----------------
Method [ <internal:PDO> public method fetchObject ] {
- Parameters [2] {
Parameter #0 [ <optional> $class_name ]
Parameter #1 [ <optional> $ctor_args ]
}
}
object(stdClass)#3 (1) {
["id"]=>
string(1) "5"
}
Actual result:
--------------
Strict Standards: Declaration of secondPDOStatement::fetchObject() should
be compatible with that of PDOStatement::fetchObject() in
/home/dev-olivier/pdoTest.php on line 13
Method [ <internal:PDO> public method fetchObject ] {
- Parameters [2] {
Parameter #0 [ <required> $class_name ]
Parameter #1 [ <optional> $ctor_args ]
}
}
object(stdClass)#3 (1) {
["id"]=>
string(1) "5"
}
--
Edit bug report at http://bugs.php.net/?id=46157&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46157&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46157&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46157&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46157&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=46157&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46157&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46157&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46157&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46157&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46157&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46157&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46157&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46157&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46157&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46157&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46157&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46157&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46157&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46157&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46157&r=mysqlcfg