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

From: Date: Mon, 16 Oct 2017 10:25:11 +0000
Subject: Bug #75387 [NEW]: fetchAll complains about extraneous parameters
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211715@lists.php.net to get a copy of this message
From: aljosha dot papsch at vinexus dot eu Operating system: PHP version: 7.1.10 Package: PDO Core Bug Type: Bug Bug description:fetchAll complains about extraneous parameters 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 bug report at https://bugs.php.net/bug.php?id=75387&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75387&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75387&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75387&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75387&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75387&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75387&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75387&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75387&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75387&r=support Expected behavior: https://bugs.php.net/fix.php?id=75387&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75387&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75387&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75387&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75387&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75387&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75387&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75387&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75387&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75387&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75387&r=mysqlcfg

« previous php.bugs (#211715) next »