php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-23 23:10 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC