Skip to content
Snippets Groups Projects
Commit 9ecadecd authored by Stefan Bürk's avatar Stefan Bürk
Browse files

[TASK] Avoid implicitly nullable parameter on `DatabaseRecordException`

With PHP 8.4 marking method parameter implicitly nullable
is depreacted and will emit a `E_DEPRECATED` warning. One
recommended way to resolve this, is making it explicitly
nullable using the `?` nullable operator. [1]

In cases, where are implicitly nullable parameter exists
before not-nullable parameters in a method or constructor,
making it explicitly nullable will emit a

  Optional parameter <paramname> declared before required
  parameter <paramname> is implicitly treated as a required
  parameter

since PHP 8.0 [2].

This change removes the `null` default value and adds the `?`
nullable operator to the previousException parameter for the
`\TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException`
constructor.

This prepares the way towards PHP 8.4 compatibility.

[1] https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated
[2] https://php.watch/versions/8.0/deprecate-required-param-after-optional

Resolves: #103926
Releases: main, 12.4, 11.5
Change-Id: I4d1506b24b3113a74b37b986fa4f23f24e6219fb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84361


Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 2ca2b2d2
Branches
Tags
No related merge requests found
......@@ -37,11 +37,11 @@ class DatabaseRecordException extends Exception
*
* @param string $message Human readable error message
* @param int $code Exception code timestamp
* @param \Exception $previousException Possible exception from database layer
* @param \Exception|null $previousException Possible exception from database layer
* @param string $tableName Table name query was working on
* @param int $uid Table row uid
*/
public function __construct($message, $code, \Exception $previousException = null, $tableName, $uid)
public function __construct($message, $code, ?\Exception $previousException, string $tableName, int $uid)
{
parent::__construct($message, $code, $previousException);
$this->tableName = $tableName;
......
......@@ -42,6 +42,8 @@ abstract class AbstractDatabaseRecordProvider implements LoggerAwareInterface
*/
protected function getRecordFromDatabase($tableName, $uid)
{
// @todo Remove int cast after making method parameters native typed.
$uid = (int)$uid;
if ($uid <= 0) {
throw new \InvalidArgumentException(
'$uid must be positive integer, ' . $uid . ' given',
......@@ -57,7 +59,7 @@ abstract class AbstractDatabaseRecordProvider implements LoggerAwareInterface
1437656081,
null,
$tableName,
(int)$uid
$uid
);
}
return $row;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment