Bug #79469 [Opn]: Property access is not allowed yet on a non-initlized connection

From: Date: Mon, 13 Apr 2020 11:32:07 +0000
Subject: Bug #79469 [Opn]: Property access is not allowed yet on a non-initlized connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226552@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79469&edit=1 ID: 79469 Updated by: cmb@php.net Reported by: morozov at tut dot by Summary: Property access is not allowed yet on a non-initlized connection Status: Open Type: Bug Package: MySQLi related Operating System: Linux PHP Version: master-Git-2020-04-12 (Git) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-04-13 00:02:10] bugreports at gmail dot com > var_dump(mysqli_init()->sqlstate); that code make sno sense at all ------------------------------------------------------------------------ [2020-04-12 19:00:51] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79469&edit=1

« previous php.bugs (#226552) next »