Edit report at http://bugs.php.net/bug.php?id=54545&edit=1
ID: 54545 Updated by: cataphr...@php.net Reported by: php at bucksvsbytes dot com Summary: PDO::query throws exceptions with null optional arguments Status: Open Type: Bug Package: PDO related Operating System: ubuntu PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: > The only problem is that a null argument should be equivalent to an omitted > argument for error checking purposes I don't know where you got this idea. An omitted argument should be equivalent to whatever initializer is specified. The documentation of PDO::query doesn't show any initializers, so you can't assume you can pass NULLs. The fact this rule is only conventional in internal functions (there's no enforced initializer functionality) doesn't make it less true; if an initializer in the docs don't match the behavior, it's a bug. That said, it might be appropriate to have nulls have the same effect as missing arguments. Previous Comments: ------------------------------------------------------------------------ [2011-04-16 20:57:36] php at bucksvsbytes dot com 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. ------------------------------------------------------------------------ [2011-04-16 19:47:05] johan...@php.net Which driver are you using? What's the PHP configure line? And well ... verification on 5.3.6 or svn snapshot would be great ... Please also mind that if you're using distribution packages you might issues due to their patches, which we can't verify. ------------------------------------------------------------------------ [2011-04-16 07:59:11] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54545&edit=1