php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53647 mysql_num_rows falsely returns NULL on error
Submitted: 2011-01-04 12:18 UTC Modified: 2011-01-04 13:02 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: justus at abi007 dot info Assigned:
Status: Not a bug Package: MySQL related
PHP Version: Irrelevant OS: Ubuntu 10 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: justus at abi007 dot info
New email:
PHP Version: OS:

 

 [2011-01-04 12:18 UTC] justus at abi007 dot info
Description:
------------
mysql_num_rows returns NULL for invalid input data, like Strings/Booleans/Null/etc. 
In regards to the documentation this should be bool(false)

http://php.net/mysql_num_rows
"Return Values
The number of rows in a result set on success or FALSE on failure."

Because it is likely better that invalid input data leads to a different failure handling I propose that you add "or NULL for invalid input data" to the documentation of Return Values to fix this.

Test script:
---------------
<? 
var_dump(mysql_num_rows('test'));
?>

Expected result:
----------------
bool(false)

Actual result:
--------------
Warning: mysql_num_rows() expects parameter 1 to be resource, string given in - on line 2
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-04 13:02 UTC] aharvey@php.net
-Status: Open +Status: Bogus -Type: Documentation Problem +Type: Bug
 [2011-01-04 13:02 UTC] aharvey@php.net
Failed parameter checks within PHP functions result in NULL being
returned. This is expected (and standard) behaviour across the PHP
standard library.

Closing.
 [2011-01-04 13:17 UTC] justus at abi007 dot info
That this is the expected behaviour is the point, because the documentation implies it isn't.

Please correct me if I'm wrong, but this "standard behaviour" is undocumented behaviour and thus useless. If this means writing the proposed update into every "Result Values" field, then so be it, right now it's not even close to ideal.

Regards,
Justus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC