php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43934 uncaught exception for wrong parameter type in mysql_fetch_object
Submitted: 2008-01-25 11:43 UTC Modified: 2008-10-27 12:59 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: josmessa at uk dot ibm dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2CVS-2008-01-25 (snap) OS: Windows XP
Private report: No CVE-ID: None
 [2008-01-25 11:43 UTC] josmessa at uk dot ibm dot com
Description:
------------
If an argument that is not an array or null is passed as the $params (also called $ctor_params in source code) argument in mysql_fetch_object then the below uncaught exception is returned instead of a normal warning. 
The reproduced code below is similar to that of a test case from 5.3, although by the time that what I have described above was tested no more rows were in $res so bool(false) was being returned and so this problem may also be in 5.3

Reproduce code:
---------------
<?php
//select database and table...

$res = mysql_query('SELECT col1 FROM test');

class mysql_fetch_object_test {
	public $a = null;
	public $b = null;
	public function __construct($a, $b) {
		$this->a = $a;
		$this->b = $b;
	}
	public function toString() {
		var_dump($this);
	}
}
var_dump(mysql_fetch_object($res, 'mysql_fetch_object_test', 'not array'));
?>

Actual result:
--------------
Fatal error: Uncaught exception 'Exception' with message 'Parameter ctor_params must be an array' in ...\mysql_fetch_object.php:25
Stack trace:
#0 ...\mysql_fetch_object.php(25): mysql_fetch_object(Resource id #5, 'mysql_fetch_obj...', 'not array')
#1 {main}
  thrown in ...\mysql_fetch_object.php on line 25


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-07 19:53 UTC] felipe@php.net
The comments on code justify such behavior:

/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
* by mistake and the other way round is possible, too. The 
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
 [2008-10-27 12:59 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC