Problem/Motivation
PHP 8.0 is now released, and we recently committed the MySQL 8 compatibility fixes to core. I waited for that issue before submitting this ticket.
A major change in PHP 8.0 is
Fatal errors on incompatible method signatures, and the first fatal error from the signature mismatch in \DatabaseConnection::runQuery($query, array $args = array(), $options = array()), that overrides \PDO::query($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = array()).
As you can see, the $args parameter is widely used within Drupal, but it not compatible with PDO::query, which now results in fatal error.
Steps to reproduce
- Update to PHP 8.0
- Open site.
Proposed resolution
Because we extendPDO class, rather than composing with it, it is not possible to seamlessly update this method.
Drupal fortunately encapsulates the \DatabaseConnection::query($query, array $args = array(), $options = array()) method, and use the classes that extend the DatabaseConnection class, so we can renamequery method to a new one, and leave PDO::query method intact.
I went ahead and refactored DatabaseConnection::query() method to runQuery, and it worked!
This of course, is the solution I could come up with, and is not an elegant one. I'd love to hear any other alternative approaches.
Remaining tasks
None.
User interface changes
None.
API changes
- Communicate this change. DatabaseConnection::query is declared public (as all methods in Drupal 7 are), so we will need to communicate this change.
Data model changes
None.
Release notes snippet
Due to PHP 8.0's signature checks on LSP,
DatabaseConnection::querymethod was renamed toDatabaseConnection::runQuery. All database drivers will now need to rename to this method for PHP 8.0 compatibility.