|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-04-16 07:59 UTC] php at bucksvsbytes dot com
Description:
------------
In 5.3.3 (sorry, I can't load 5.3.6 to confirm), supplying the optional fetchmode arguments (args 2,3,4) as NULL throws fatal exceptions. In 5.2, those arguments as NULL were ignored. Optional arguments supplied as NULL should always be ignored unless the NULL is significant to the logic. It looks to me like you now have to call PDO::query with exactly the right number of arguments (1, 2, 3, or 4) to avoid bombing the script.
Test script:
---------------
$db=new PDO($dsn);
unset($fetchmode,$fetch2,$fetch3);
$db->query('select * from table',$fetchmode,$fetch2,$fetch3);
//throws fatal exception
$fetchmode=0;
$db->query('select * from table',$fetchmode,$fetch2,$fetch3);
//throws different fatal exception
Expected result:
----------------
I expect query to ignore fetchmode when it is null.
Actual result:
--------------
query fails fatally
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
It doesn't appear to be a package issue to me. The error is caused by specific checking of the argument values, proved by the different exceptions below. The only problem is that a null argument should be equivalent to an omitted argument for error checking purposes. These exception appeared after switching from a 5.2 PHP server to a 5.3. Example 1 (arg2, arg3, and arg4 of query are null): exception 'PDOException' with message 'SQLSTATE[HY000]: General error: mode must be an integer' in /home/bvb/www/html/cl/bvc_d.php:681 Stack trace: #0 /home/bvb/www/html/cl/bvc_d.php(681): PDO->query('select * from p...', NULL, NULL, NULL) Example 2 (arg2 of query is 0, arg3 and arg4 are null): exception 'PDOException' with message 'SQLSTATE[HY000]: General error: fetch mode doesn't allow any extra arguments' in /home/bvb/www/html/cl/bvc_d.php:681 Stack trace: #0 /home/bvb/www/html/cl/bvc_d.php(681): PDO->query('select * from p...', 0, NULL, NULL) My PDO driver is pgsql. The Configure Command display of phpinfo() is missing in 5.3, so please advise what equivalent data I should supply for the PHP configure line.Your point about initializers is absolutely correct, of course, but it seems unnecessarily cumbersome (and atypical in PHP) to require this awkward construction: if ($a) then{ $x=function($p1) }elseif($b) then{ $x=function($p1,$p2) }elseif($c) then{ $x=function($p1,$p2,$p3) } rather than simply $x=function($p1,$p2,$p3) with the value of p2 and p3 determining which function logic to execute. I leave it in your hands. Thanks for your responses.Closing this as Won't Fix. In PHP 8, the signature for PDO::query() is: public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) {} which now gives explicit indication that the method accepts a variable number of arguments. If you need to call query() generically, using different fetch modes, then you can also use argument unpacking to do so: public function myQuery(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) { return $this->pdo->query($query, $fetchMode, ...$fetchModeArgs); }