From ca1560f89c092af013220c64fbe7f2195e2a82ad Mon Sep 17 00:00:00 2001 From: Maciej Holyszko <14310995+falkenhawk@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:52:32 +0200 Subject: [PATCH] [zend-exception] allow Throwable in $previous The constructor overload must stay because zf1 relies on code being casted to int there in many places (e.g. exceptions coming from PDO, which may have `long` or `string` codes...) Relax the type declaration to allow passing any type (as typing `Throwable` would not work in php 5.x) and just let the base `Exception` class check and throw on invalid type. --- packages/zend-db/library/Zend/Db/Statement/Pdo.php | 6 +++--- packages/zend-exception/library/Zend/Exception.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/zend-db/library/Zend/Db/Statement/Pdo.php b/packages/zend-db/library/Zend/Db/Statement/Pdo.php index 871420048..0eb1413a0 100644 --- a/packages/zend-db/library/Zend/Db/Statement/Pdo.php +++ b/packages/zend-db/library/Zend/Db/Statement/Pdo.php @@ -254,7 +254,7 @@ public function fetch($style = null, $cursor = null, $offset = null) return $this->_stmt->fetch($style, $cursor, $offset); } catch (ValueError $e) { // PHP 8.0+ throws ValueError on invalid arguments - throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode()); + throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); } catch (PDOException $e) { // require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); @@ -295,7 +295,7 @@ public function fetchAll($style = null, $col = null) } } catch (ValueError $e) { // PHP 8.0+ throws ValueError on invalid arguments - throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode()); + throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); } catch (PDOException $e) { // require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); @@ -439,7 +439,7 @@ public function setFetchMode($mode) return $this->_stmt->setFetchMode($mode); } catch (ValueError $e) { // PHP 8.0+ throws ValueError on invalid arguments - throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode()); + throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); } catch (PDOException $e) { // require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); diff --git a/packages/zend-exception/library/Zend/Exception.php b/packages/zend-exception/library/Zend/Exception.php index 4eda3d7db..3ec4acf1d 100644 --- a/packages/zend-exception/library/Zend/Exception.php +++ b/packages/zend-exception/library/Zend/Exception.php @@ -32,10 +32,10 @@ class Zend_Exception extends Exception * * @param string $msg * @param int $code - * @param Exception $previous + * @param Exception|Throwable $previous * @return void */ - public function __construct($msg = '', $code = 0, Exception $previous = null) + public function __construct($msg = '', $code = 0, $previous = null) { parent::__construct($msg, (int) $code, $previous); }