diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 682c742f1..fb8a3455e 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -333,7 +333,7 @@ class Mysql extends DboSource { * Returns an array of the fields in given table name. * * @param Model|string $model Name of database table to inspect or model instance - * @return array Fields in table. Keys are name and type + * @return array|bool Fields in table. Keys are name and type. Returns false if result is empty. * @throws CakeException */ public function describe($model) { @@ -344,7 +344,7 @@ class Mysql extends DboSource { } $table = $this->fullTableName($model); - $fields = false; + $fields = array(); $cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $table); if (!$cols) { throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table)); @@ -361,7 +361,8 @@ class Mysql extends DboSource { $fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type); } if (in_array($fields[$column->Field]['type'], array('timestamp', 'datetime')) && - in_array(strtoupper($column->Default), array('CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP()')) + //Falling back to default empty string due to PHP8.1 deprecation notice. + in_array(strtoupper($column->Default ?? ""), array('CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP()')) ) { $fields[$column->Field]['default'] = null; } @@ -382,6 +383,12 @@ class Mysql extends DboSource { } $this->_cacheDescription($key, $fields); $cols->closeCursor(); + + //Fields must be an array for compatibility with PHP8.1 (deprecation notice) but also let's keep backwards compatibility for method. + if (count($fields) === 0) { + return false; + } + return $fields; } diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ebfab0a97..342ff9d17 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2070,7 +2070,8 @@ class DboSource extends DataSource { * @return string */ public function renderJoinStatement($data) { - if (strtoupper($data['type']) === 'CROSS' || empty($data['conditions'])) { + //Fixed deprecation notice in PHP8.1 - fallback to empty string + if (strtoupper($data['type'] ?? "") === 'CROSS' || empty($data['conditions'])) { return "{$data['type']} JOIN {$data['table']} {$data['alias']}"; } return trim("{$data['type']} JOIN {$data['table']} {$data['alias']} ON ({$data['conditions']})"); diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 85dbb59c9..8149ce39a 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -470,7 +470,8 @@ class CakeRoute { //check patterns for routed params if (!empty($this->options)) { foreach ($this->options as $key => $pattern) { - if (array_key_exists($key, $url) && !preg_match('#^' . $pattern . '$#', $url[$key])) { + //Fixing deprecation notice about null $subject in PHP8.1. + if (array_key_exists($key, $url) && !preg_match('#^' . $pattern . '$#', $url[$key] ?? "")) { return false; } }