|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-09-23 23:10 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 19:00:02 2025 UTC |
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" }