I overloaded query
method of mysqli
class like so:
class MySql extends \mysqli
{
function query(string $sql): ?MySqlResult // line #30
{
$result = parent::query($sql);
return new MySqlResult($result);
}
}
in PHP8.0 that was not an issue. However, as of PHP8.1 I am now getting this error:
Deprecated: Return type of
Repository\MySql\MySql::query($sql, $resultmode = null)
should either be compatible withmysqli::query(string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool
, or the#[\ReturnTypeWillChange]
attribute should be used to temporarily suppress the notice inrepository\src\MySql\MySql.php
on line 30
I know how to fix the error - I will probably end up changing the name of the method, since I want to return a my own custom object.
Question
I am looking for an answer that captures the need for this change from a theoretical and object-oriented perspective, maybe using language theory, or comparing it to other languages.
Why was this change necessary? What was the need or what was the reason to make this change? What there a way to allow overloaded return types in PHP when extending a class?