Skip to content

Commit 28cff8a

Browse files
authored
Fix some PHP 8.1 warnings (#4012)
* Fix some PHP 8.1 warnings The proper fix will have to wait till be drop PHP7. #fix #4010 * Another PHP8.1 fix
1 parent b21fe19 commit 28cff8a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lib/Minz/Pdo.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,31 @@ protected function preSql($statement) {
2828
return $this->autoPrefix($statement);
2929
}
3030

31+
// PHP8+: PDO::lastInsertId(?string $name = null): string|false
32+
#[\ReturnTypeWillChange]
3133
public function lastInsertId($name = null) {
3234
if ($name != null) {
3335
$name = $this->preSql($name);
3436
}
3537
return parent::lastInsertId($name);
3638
}
3739

40+
// PHP8+: PDO::prepare(string $query, array $options = []): PDOStatement|false
41+
#[\ReturnTypeWillChange]
3842
public function prepare($statement, $driver_options = array()) {
3943
$statement = $this->preSql($statement);
4044
return parent::prepare($statement, $driver_options);
4145
}
4246

47+
// PHP8+: PDO::exec(string $statement): int|false
48+
#[\ReturnTypeWillChange]
4349
public function exec($statement) {
4450
$statement = $this->preSql($statement);
4551
return parent::exec($statement);
4652
}
4753

54+
// PHP8+: PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs): PDOStatement|false
55+
#[\ReturnTypeWillChange]
4856
public function query($query, $fetch_mode = null, ...$fetch_mode_args) {
4957
$query = $this->preSql($query);
5058
return $fetch_mode ? parent::query($query, $fetch_mode, ...$fetch_mode_args) : parent::query($query);

lib/Minz/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private static function initJSON() {
415415
* @return string
416416
*/
417417
private static function extractContentType() {
418-
return strtolower(trim(static::getHeader('CONTENT_TYPE')));
418+
return strtolower(trim(static::getHeader('CONTENT_TYPE', '')));
419419
}
420420

421421
/**
@@ -454,7 +454,7 @@ public static function isPost() {
454454
* @return array
455455
*/
456456
public static function getPreferredLanguages() {
457-
if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', static::getHeader('HTTP_ACCEPT_LANGUAGE'), $matches)) {
457+
if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', static::getHeader('HTTP_ACCEPT_LANGUAGE', ''), $matches)) {
458458
return $matches['lang'];
459459
}
460460
return array('en');

lib/lib_rss.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function html_only_entity_decode($text) {
165165
get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities
166166
));
167167
}
168-
return strtr($text, $htmlEntitiesOnly);
168+
return $text == '' ? '' : strtr($text, $htmlEntitiesOnly);
169169
}
170170

171171
function customSimplePie($attributes = array()) {

0 commit comments

Comments
 (0)