File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
src/DebugBar/DataCollector/PDO Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -114,9 +114,12 @@ public function getSqlWithParams(string $quotationChar = '<>') : string
114114
115115 foreach ($ this ->parameters as $ k => $ v ) {
116116
117- $ backRefSafeV = strtr ($ v , $ cleanBackRefCharMap );
118-
119- $ v = "$ quoteLeft$ backRefSafeV$ quoteRight " ;
117+ if (null === $ v ) {
118+ $ v = 'NULL ' ;
119+ } else {
120+ $ backRefSafeV = strtr ($ v , $ cleanBackRefCharMap );
121+ $ v = "$ quoteLeft$ backRefSafeV$ quoteRight " ;
122+ }
120123
121124 if (is_numeric ($ k )) {
122125 $ marker = "\? " ;
Original file line number Diff line number Diff line change @@ -119,6 +119,37 @@ public function testReplacementParamsContainingPotentialAdditionalNamedPlacehold
119119 $ this ->assertEquals ($ expected , $ result );
120120 }
121121
122+ /**
123+ * Check if literal `NULL` query parameters are replaced without triggering a deprecation warning since PHP 8.0.0.
124+ * This can happen when e.g. binding `PDO::PARAM_NULL` to your prepared statement.
125+ *
126+ * @link https://www.php.net/manual/en/migration81.deprecated.php#migration81.deprecated.core.null-not-nullable-internal
127+ */
128+ public function testReplacementParamsContainingLiteralNullValueGeneratesCorrectString ()
129+ {
130+ $ sql = 'UPDATE user SET login_failed_reason = :nullable_reason WHERE id = :id ' ;
131+
132+ $ params = [
133+ 'id ' => 1234 ,
134+ 'nullable_reason ' => 'Life happens ' ,
135+ ];
136+
137+ $ traced = new TracedStatement ($ sql , $ params );
138+ $ expected = 'UPDATE user SET login_failed_reason = "Life happens" WHERE id = "1234" ' ;
139+ $ result = $ traced ->getSqlWithParams ('" ' );
140+ $ this ->assertEquals ($ expected , $ result );
141+
142+ $ params = [
143+ 'id ' => 1234 ,
144+ 'nullable_reason ' => null ,
145+ ];
146+
147+ $ traced = new TracedStatement ($ sql , $ params );
148+ $ expected = 'UPDATE user SET login_failed_reason = NULL WHERE id = "1234" ' ;
149+ $ result = $ traced ->getSqlWithParams ('" ' );
150+ $ this ->assertEquals ($ expected , $ result );
151+ }
152+
122153 /**
123154 * Check if query parameters are being replaced in the correct way
124155 * @bugFix Before fix it : select *
You can’t perform that action at this time.
0 commit comments