php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79591 mysqli::$errno not an integer after connection close
Submitted: 2020-05-12 15:56 UTC Modified: 2023-01-10 16:02 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: vedad at kajtaz dot net Assigned:
Status: Wont fix Package: MySQLi related
PHP Version: 7.4.5 OS: FreeBSD 12.1-RELEASE
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vedad at kajtaz dot net
New email:
PHP Version: OS:

 

 [2020-05-12 15:56 UTC] vedad at kajtaz dot net
Description:
------------
The documentation states that mysqli::$errno is an integer.

Once the mysqli connection was closed, it resolves to boolean false instead.

This is annoying when mysqli::$errno is being passed as second argument to \Throwable, which triggers an Error with strict_types enabled.

Test script:
---------------
$mysqli = mysqli_init();

assert(is_int($mysqli->errno) && 'before connect');

assert($mysqli->real_connect(...));

assert(is_int($mysqli->errno) && 'before close');

$mysqli->close();

assert(is_int($mysqli->errno) && 'after close');


Actual result:
--------------
PHP Fatal error:  Uncaught AssertionError: assert(is_int($mysqli->errno) && 'after close')

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-12 17:13 UTC] vedad at kajtaz dot net
Somehow related, there is also mysqli::$info resolving to null instead of empty string, as stated in the documentation:

> Queries which do not fall into one of the preceding formats are not supported. In these situations, mysqli_info() will return an empty string.
 [2020-05-13 09:34 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-05-13 09:34 UTC] cmb@php.net
After closing the connection, the connection is no longer valid.
In PHP 7 this should trigger a warning like "Couldn't fetch
mysqli".  In PHP 8 the warning will be elevated to an exception
("mysqli object is already closed").  So you really should not
access a closed mysqli object.

So this is not a bug, but it makes sense to document this behavior
more prominently.
 [2020-05-13 12:23 UTC] vedad at kajtaz dot net
Thanks, I agree with the Exception approach, and a documentation fix meanwhile.

The mysqli::$info issue I mentioned in a comment is unrelated to the connection being closed, should I file a separate bug?
 [2023-01-10 16:02 UTC] dharman@php.net
-Status: Open +Status: Wont fix
 [2023-01-10 16:02 UTC] dharman@php.net
As this is only relevant for PHP 7 which has reached EOL I see no reason to keep this open anymore. I also don't think it should be documented as this is not something that should be done on purpose. In this regard, I would treat it more as undefined behaviour. Using a closed object would generate a warning and return false from whichever function you tried to use. I am glad we got rid of warnings.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC