Skip to content

Commit 71ff3b5

Browse files
committed
Improve PHP 8 compatibility
Trying to access non-existent array fields is a warning in PHP 8. Though this error is masked by ddeboer/transcoder#5 in the integration tests when mbstring extension is available. Also, Dice uses `ReflectionParameter::getClass()`, which is deprecated in PHP 8. Since we have not yet set an error handler at that point because it needs a `Logger` class instantiated by Dice, let’s disable deprecation warnings temporarily. Unfortunately, we cannot just re-enable them and log them in the error handler since fatfree’s error handler is extremely inflexible bcosca/fatfree#999.
1 parent adaf0e8 commit 71ff3b5

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/common.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
$f3 = Base::instance();
2727

28+
// Disable deprecation warnings.
29+
// Dice uses ReflectionParameter::getClass(), which is deprecated in PHP 8
30+
// but we have not set an error handler yet because it needs a Logger instantiated by Dice.
31+
error_reporting(E_ALL & ~E_DEPRECATED);
32+
2833
$f3->set('DEBUG', 0);
2934
$f3->set('version', '2.19-SNAPSHOT');
3035

@@ -203,6 +208,7 @@
203208

204209
// init logger
205210
$log = $dice->create(Logger::class);
211+
206212
if ($f3->get('logger_level') === 'NONE') {
207213
$handler = new NullHandler();
208214
} else {

src/controllers/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ private function loadItems(array $params, array $tags) {
127127
$itemsHtml = '';
128128

129129
$firstPage = $params['offset'] == 0
130-
&& $params['fromId'] == ''
131-
&& $params['fromDatetime'] == '';
130+
&& (!isset($params['fromId']) || $params['fromId'] == '')
131+
&& (!isset($params['fromDatetime']) || $params['fromDatetime'] == '');
132132
if ($params['source'] && $this->authentication->allowedToUpdate() && $firstPage) {
133133
$itemsHtml = '<button type="button" id="refresh-source" class="refresh-source">' . \F3::get('lang_source_refresh') . '</button>';
134134
}

src/controllers/Sources/Write.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ public function write(Base $f3, array $params) {
8383
}
8484
$tags = array_map('htmlspecialchars', $data['tags']);
8585
$spout = $data['spout'];
86-
$filter = $data['filter'];
86+
$filter = isset($data['filter']) ? $data['filter'] : null;
8787

8888
unset($data['title']);
8989
unset($data['spout']);
9090
unset($data['filter']);
9191
unset($data['tags']);
9292

9393
// check if source already exists
94-
$id = $params['id'];
95-
$sourceExists = $this->sourcesDao->isValid('id', $id);
94+
$id = isset($params['id']) ? $params['id'] : null;
95+
$sourceExists = $id !== null && $this->sourcesDao->isValid('id', $id);
9696

9797
// load password value if not changed for spouts containing passwords
9898
if ($sourceExists) {

src/helpers/ContentLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ public function fetch($source) {
215215
'datetime' => $itemDate->format('Y-m-d H:i:s'),
216216
'uid' => $item->getId(),
217217
'link' => htmLawed($item->getLink(), ['deny_attribute' => '*', 'elements' => '-*']),
218-
'author' => $author
218+
'author' => $author,
219+
'thumbnail' => null,
220+
'icon' => null,
219221
];
220222

221223
$thumbnailUrl = $item->getThumbnail();

0 commit comments

Comments
 (0)