php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46858 Incorrect isset result on MySQLi_Result properties (only in PHP_5_2)
Submitted: 2008-12-13 16:46 UTC Modified: 2009-08-27 10:59 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: eric at livejournal dot dk Assigned: andrey (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.9 OS: *
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: eric at livejournal dot dk
New email:
PHP Version: OS:

 

 [2008-12-13 16:46 UTC] eric at livejournal dot dk
Description:
------------
isset returns false when applied to a MySQLi_result object that does indeed exist.

Reproduce code:
---------------
<?php
$db = new mysqli('localhost', 'test', 'test', 'test');
$result = $db->query('SELECT * FROM test;'); //contains 1 row

echo $result->num_rows;

if (isset($result->num_rows))
	echo 'defined';
else
	echo 'undefined';

?>

Expected result:
----------------
1defined

Actual result:
--------------
1undefined

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 15:28 UTC] jani@php.net
Why do you test if that property exists anyway? It's always there, you don't need to test for that. :)
 [2008-12-31 16:11 UTC] eric at livejournal dot dk
The property doesn't exist if the query failed. I realise I could simply check the error member, but I figured I'd still report it because IMO a bug exists - isset incorrectly returns false.
 [2009-04-13 17:26 UTC] jani@php.net
Andrey, any possibility to fix this also in PHP_5_2 ? 
(See bug #44352)
 [2009-08-27 10:59 UTC] andrey@php.net
Interesting,
I find this bogus, as if the query has failed $result won't be an object but a boolean value.

Here is the real bug, a Zend Engine bug:
andrey@winnie:/work/mysql-server/mysql-5.1/sql$ php -r '$a=true;var_dump($a);var_dump(isset($a->b));'
bool(true)
bool(false)

It doesn't fail although $a is not an object.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 21:03:16 2021 UTC