Skip to content

Commit 6b52092

Browse files
committed
Added PDOException wrapper to avoid creating dynamic property.
1 parent 7e1da9a commit 6b52092

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ It means that composer will look at `master` branch of repository configured und
5959

6060
## Changelog
6161

62+
### 2024-09-21
63+
64+
- Added wrapper for PDOException to avoid creating dynamic property `queryString`.
65+
6266
### 2024-07-24
6367

6468
- Csrf vulnerabity fix back ported from Cake PHP 3

lib/Cake/Model/Datasource/DboSource.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
App::uses('DataSource', 'Model/Datasource');
20+
App::uses('PDOExceptionWithQueryString', 'Model/Datasource');
2021
App::uses('CakeText', 'Utility');
2122
App::uses('View', 'View');
2223

@@ -512,12 +513,13 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
512513
}
513514
return $query;
514515
} catch (PDOException $e) {
516+
$wrapperException = new PDOExceptionWithQueryString($e);
515517
if (isset($query->queryString)) {
516-
$e->queryString = $query->queryString;
518+
$wrapperException->queryString = $query->queryString;
517519
} else {
518-
$e->queryString = $sql;
520+
$wrapperException->queryString = $sql;
519521
}
520-
throw $e;
522+
throw $wrapperException;
521523
}
522524
}
523525

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
class PDOExceptionWithQueryString extends PDOException {
4+
5+
public string $queryString = "";
6+
7+
/**
8+
* Wrapper for PDOException to avoid creating dynamic property.
9+
*
10+
* @param PDOException $e Source exception.
11+
*/
12+
public function __construct(PDOException $e) {
13+
parent::__construct($e->getMessage(), 0, $e->getPrevious());
14+
15+
$this->code = $e->code;
16+
}
17+
}

0 commit comments

Comments
 (0)