Bug #75387 [Com]: fetchAll complains about extraneous parameters

From: Date: Wed, 18 Oct 2017 07:39:03 +0000
Subject: Bug #75387 [Com]: fetchAll complains about extraneous parameters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211768@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75387&edit=1 ID: 75387 Comment by: yannis dot berrouag at gmail dot com Reported by: aljosha dot papsch at vinexus dot eu Summary: fetchAll complains about extraneous parameters Status: Open Type: Bug Package: PDO Core PHP Version: 7.1.10 Block user comment: N Private report: N New Comment: I don't think it's a good idea, you are trying to use a function incorrectly and php warns you about that, this is a perfectly normal behavior. if you are writing a wrapper, why don't you just write yourself simpler methods like fetchAssoc(), fetchBoth() etc ... and make the correct call to fetchAll inside. Previous Comments: ------------------------------------------------------------------------ [2017-10-16 10:25:04] aljosha dot papsch at vinexus dot eu Description: ------------ I created a small wrapper around PDO. My first stab at wrapping fetchAll looked like this: public function fetchAll($fetchStyle = \PDO::FETCH_BOTH, $fetchArgument = null, array $constructorArgs) { return $this->st->fetchAll($fetchStyle, $fetchArgument, $constructorArgs); } PDO rejected the method call, complaining: SQLSTATE[HY000]: General error: Extraneous additional parameters So I had to turn the simple one liner into: public function fetchAll($fetchStyle = \PDO::FETCH_BOTH, $fetchArgument = null, array $constructorArgs = []) { if ($fetchStyle === \PDO::FETCH_BOTH) { return $this->st->fetchAll(); } elseif ($fetchStyle === \PDO::FETCH_CLASS) { return $this->st->fetchAll($fetchStyle, $fetchArgument, $constructorArgs); } elseif ($fetchStyle === \PDO::FETCH_ASSOC || $fetchStyle === \PDO::FETCH_NUM || $fetchStyle === \PDO::FETCH_ASSOC) { return $this->st->fetchAll($fetchStyle); } else { return $this->st->fetchAll($fetchStyle, $fetchArgument); } } It would be great if PDO would not complain about extraneous arguments and just ignore arguments not needed. Otherwise, any PDO wrapper has to do this logic again of its own, possibly with errors. For example, there is a bug in the code above: I forgot considering \PDO::FETCH_OBJ in the last elseif block. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75387&edit=1

« previous php.bugs (#211768) next »