PHP :: Bug #46157 :: PDOStatement::fetchObject prototype error
| Bug #46157 | PDOStatement::fetchObject prototype error | ||||
|---|---|---|---|---|---|
| Submitted: | 2008-09-23 10:15 UTC | Modified: | 2008-09-23 23:10 UTC | ||
| From: | ob dot php at daevel dot fr | Assigned: | felipe (profile) | ||
| Status: | Closed | Package: | PDO related | ||
| PHP Version: | 5.2.6 | OS: | Linux | ||
| Private report: | No | CVE-ID: | None | ||
[2008-09-23 10:15 UTC] ob dot php at daevel dot fr
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"
}
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2008-09-23 23:10 UTC] felipe@php.net