php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79469 Property access is not allowed yet on a non-initlized connection
Submitted: 2020-04-12 19:00 UTC Modified: 2020-04-13 11:32 UTC
From: morozov at tut dot by Assigned:
Status: Open Package: MySQLi related
PHP Version: master-Git-2020-04-12 (Git) OS: Linux
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: morozov at tut dot by
New email:
PHP Version: OS:

 

 [2020-04-12 19:00 UTC] morozov at tut dot by
Description:
------------
When handling connection exceptions, Doctrine DBAL uses the mysqli::$sqlstate property of the connection. Prior to PHP 8, access to the property of a non-initialized connection would result in a warning and returned false: In PHP 8 the warning got promoted to a fatal error.

There doesn't seem to be a way to see if the connection is initialized, so it might make sense to just return false there and not raise an error.

Additionally, the possible false value of the property is not documented in https://www.php.net/manual/en/class.mysqli.php which leads to false-positive issues during static analysis.

Test script:
---------------
var_dump(mysqli_init()->sqlstate);

Expected result:
----------------
false

Actual result:
--------------
Fatal error: Uncaught Error: Property access is not allowed yet

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-13 00:02 UTC] bugreports at gmail dot com
> var_dump(mysqli_init()->sqlstate);

that code make sno sense at all
 [2020-04-13 11:32 UTC] cmb@php.net
Well, the Error can be caught:

<?php
try {
    var_dump(mysqli_init()->sqlstate);
} catch (Error $e) {
    echo $e->getMessage(), PHP_EOL;
}
?>

Still, it may make sense to introduce a function for checking
whether a mysqli instance is connected.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC