Skip to content

Commit 7c0ab40

Browse files
committed
PHP 8: Handle more errors explicitly
The error control operator "@" has changed behavior in PHP8 and generally seems like a quite bad hack. So let's handle array/ dict access errors explicitly.
1 parent fcda8a1 commit 7c0ab40

12 files changed

+62
-33
lines changed

config.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
* Protokollfreie URLs (welche, die mit // beginnen), werden automatisch mit dem korrekten Protokoll ergänzt.
2525
* In diesem Fall wird auch ein SSL-Umschalt-Button im Header angezeigt
2626
*/
27-
if(@$_SERVER['SERVER_NAME'] == 'localhost' || @$_SERVER['SERVER_NAME'] == '0.0.0.0')
27+
if(isset($_SERVER['SERVER_NAME']) && ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '0.0.0.0'))
2828
{
2929
// keine Konfiguration -> BASEURL wird automatisch erraten
3030
}
31-
else if(@$_SERVER['SERVER_NAME'] == 'streaming.test.c3voc.de')
31+
else if(isset($_SERVER['SERVER_NAME']) && ($_SERVER['SERVER_NAME'] == 'streaming.test.c3voc.de'))
3232
{
3333
$GLOBALS['CONFIG']['BASEURL'] = '//streaming.test.c3voc.de/';
3434
}
@@ -104,7 +104,7 @@
104104
/**
105105
* Konfiguration der Room-Defaults
106106
*
107-
* Falls in der Raum-Konfiguration innerhalb der Konferenz für diese Keys nichts definiert ist,
107+
* Falls in der Raum-Konfiguration innerhalb der Konferenz für diese Keys nichts definiert ist,
108108
* fällt das System auf diese Werte zurück.
109109
*/
110110

index.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
try {
5353
if(isset($_GET['htaccess']))
5454
{
55-
$route = @$_GET['route'];
55+
$route = isset($_GET['route']) ? $_GET['route'] : "";
5656
}
5757
elseif(isset($_SERVER["REQUEST_URI"]))
5858
{
59-
$route = ltrim(@$_SERVER["REQUEST_URI"], '/');
59+
$route = ltrim($_SERVER["REQUEST_URI"], '/');
6060

6161
// serve static
6262
if($route != '' && file_exists($_SERVER["DOCUMENT_ROOT"].'/'.$route))
@@ -87,11 +87,12 @@
8787
'conference' => new GenericConference(),
8888
));
8989

90-
if(isset($GLOBALS['CONFIG']['BASEURL']) && startswith('//', @$GLOBALS['CONFIG']['BASEURL']))
90+
if(isset($GLOBALS['CONFIG']['BASEURL']) && startswith('//', $GLOBALS['CONFIG']['BASEURL']))
9191
{
92+
$mandator = isset($GLOBALS['MANDATOR']) ? $GLOBALS['MANDATOR'] : "";
9293
$tpl->set(array(
93-
'httpsurl' => forceslash(forceslash('https:'.$GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
94-
'httpurl' => forceslash(forceslash('http:'. $GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
94+
'httpsurl' => forceslash(forceslash('https:'.$GLOBALS['CONFIG']['BASEURL']).$mandator).forceslash($route).url_params(),
95+
'httpurl' => forceslash(forceslash('http:'. $GLOBALS['CONFIG']['BASEURL']).$mandator).forceslash($route).url_params(),
9596
));
9697
}
9798

lib/helper.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,20 @@ function query_data($operation, $query, $variables = [], $assoc = false, $cache
244244
if (is_null($r)) {
245245
throw new NotFoundException();
246246
}
247-
247+
248248
// TODO: add error handling?
249249
// TODO: should we return the cached value, when we did not get an answer?
250-
return $assoc ? @$r['data'] : @$r->data;
250+
if ($assoc) {
251+
if (isset($r['data'])) {
252+
return $r['data'];
253+
} else {
254+
throw new NotFoundException();
255+
}
256+
} else {
257+
if (isset($r->data)) {
258+
return $r->data;
259+
} else {
260+
throw new NotFoundException();
261+
}
262+
}
251263
}

model/Conference.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getTitle() {
2020
}
2121

2222
public function isPreviewEnabled() {
23-
if(@$GLOBALS['forceopen'])
23+
if(isset($GLOBALS['forceopen']) && $GLOBALS['forceopen'])
2424
return true;
2525

2626
if($this->has('PREVIEW_DOMAIN') && ($this->get('PREVIEW_DOMAIN') == $_SERVER['SERVER_NAME']))

model/ConferenceJson.php

+20-14
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@ public function __construct($json, $mandator)
1212
$c = $json->conference;
1313
$this->start = DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->start);
1414
$this->end = DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->end);
15-
$this->html = @$c->streamingConfig->html ?: [];
15+
$this->html = isset($c->streamingConfig->html) ? $c->streamingConfig->html : [];
1616

1717
$this->rooms = [];
18-
$rooms = (is_array(@$c->rooms) ? $c->rooms : @$c->rooms->nodes) ?: [];
18+
if (isset($c->rooms)) {
19+
if (is_array($c->rooms)) {
20+
$rooms = $c->rooms;
21+
} else {
22+
$rooms = isset($c->rooms->nodes) ? $c->rooms->nodes : [];
23+
}
24+
}
1925
foreach($rooms as $r) {
2026
if (!$r) {
2127
continue;
2228
}
2329
$this->rooms[$r->slug] = array_merge(
2430
['stream' => $r->streamId],
25-
get_object_vars($r),
26-
@get_object_vars($r->streamingConfig) ?: [],
27-
@get_object_vars($r->streamingConfig->chat) ?: []
31+
get_object_vars($r),
32+
(isset($r->streamingConfig) ? get_object_vars($r->streamingConfig) : []),
33+
(isset($r->streamingConfig->chat) ? get_object_vars($r->streamingConfig->chat) : [])
2834
);
2935
}
3036

3137
$groups = [];
3238
if ( isset($c->streamingConfig->overviewPage->sections) ) {
33-
foreach(@$c->streamingConfig->overviewPage->sections as $s) {
34-
$groups[@$s->title] = array_map(
39+
foreach($c->streamingConfig->overviewPage->sections as $s) {
40+
$groups[$s->title] = array_map(
3541
function($r) { return $r->slug; },
3642
@$s->items ?: @$s->rooms ?: []
3743
);
@@ -44,15 +50,15 @@ function($r) { return $r->slug; },
4450
$acronym = $mandator ?: $c->acronym;
4551

4652
parent::__construct(array_merge(
47-
@get_object_vars($c->streamingConfig) ?: [],
48-
@get_object_vars($c->streamingConfig->features) ?: [],
49-
@get_object_vars($c->streamingConfig->features->chat) ?: [],
53+
isset($c->streamingConfig) ? get_object_vars($c->streamingConfig) : [],
54+
isset($c->streamingConfig->features) ? get_object_vars($c->streamingConfig->features) : [],
55+
isset($c->streamingConfig->features->chat) ? get_object_vars($c->streamingConfig->features->chat) : [],
5056
[
5157
'conference' => [
5258
'title' => $c->title,
5359
'author' => $c->organizer,
5460
'description' => $c->description,
55-
'keywords' => @implode(', ', $c->keywords),
61+
'keywords' => is_array($c->keywords) ? implode(', ', $c->keywords) : "",
5662
// future TODO: change structure
5763
"relive_json" => @$c->streamingConfig->features->relive !== false ? "https://cdn.c3voc.de/relive/".$acronym."/index.json" : null,
5864
"releases" => @$c->streamingConfig->features->releases !== false ? "https://media.ccc.de/c/".$acronym : null
@@ -140,21 +146,21 @@ public function hasBannerHtml() {
140146
return !empty($this->html->banner);
141147
}
142148
public function getBannerHtml() {
143-
return @$this->html->banner;
149+
return isset($this->html->banner) ? $this->html->banner : "";
144150
}
145151

146152
public function hasFooterHtml() {
147153
return !empty($this->html->footer);
148154
}
149155
public function getFooterHtml() {
150-
return @$this->html->footer;
156+
return isset($this->html->footer) ? $this->html->footer : "";
151157
}
152158

153159
public function hasNotStartedHtml() {
154160
return !empty($this->html->not_started);
155161
}
156162
public function getNotStartedHtml() {
157-
return @$this->html->not_started;
163+
return isset($this->html->not_started) ? $this->html->not_started : "";
158164
}
159165

160166
}

model/Conferences.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public static function getFinishedConferencesSorted() {
6565
}
6666

6767
public static function getLastConference() {
68-
return @Conferences::getFinishedConferencesSorted()[0];
68+
$conferences = Conferences::getFinishedConferencesSorted();
69+
return isset($conferences[0]) ? $conferences[0] : null;
6970
}
7071

7172
public static function exists($mandator) {
@@ -133,7 +134,7 @@ public static function loadConferenceConfig($mandator) {
133134
}
134135

135136
// config option for dynamic lookup feature defined below
136-
if (!@$GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) {
137+
if (isset($GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) && !$GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) {
137138
throw new NotFoundException();;
138139
}
139140

model/Feedback.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public function __construct(Conference $conference)
1010
}
1111

1212
private function get($key) {
13+
$global_feedback_elem = isset($GLOBALS['CONFIG']['FEEDBACK'][$key]) ? $GLOBALS['CONFIG']['FEEDBACK'][$key] : "";
1314
return $this->conference->has(['FEEDBACK', $key])
1415
? $this->conference->get(['FEEDBACK', $key])
15-
: @$GLOBALS['CONFIG']['FEEDBACK'][$key];
16+
: $global_feedback_elem;
1617
}
1718

1819
public function getConference() {

model/Schedule.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,15 @@ public function getScheduleToRoomSlugMapping()
364364
$this->mapping = array();
365365
foreach($this->getConference()->get('ROOMS') as $slug => $room)
366366
{
367-
$key = @$room['name'] ?: @$room['SCHEDULE_NAME'] ?: @$room['DISPLAY'] ?: $slug;
367+
// json has 'name', config.php has 'SCHEDULE_NAME' and 'DISPLAY'
368+
$key = $slug;
369+
if (isset($room['name'])) {
370+
$key = $room['name'];
371+
} elseif ($room['SCHEDULE_NAME']) {
372+
$key = $room['SCHEDULE_NAME'];
373+
} elseif ($room['DISPLAY']) {
374+
$key = $room['DISPLAY'];
375+
}
368376
$this->mapping[$key] = $slug;
369377
}
370378
}

view/allclosed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'page' => 'allclosed',
77
'title' => 'See you soon … somewhere else!',
88

9-
'next' => @$events[0],
9+
'next' => isset($events[0]) ? $events[0] : null,
1010
'events' => $events,
1111
'last' => Conferences::getLastConference(),
1212
));

view/closed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
'page' => 'closed',
77
'title' => 'See you soon … somewhere else!',
88

9-
'next' => @$events[0],
9+
'next' => isset($events[0]) ? $events[0] : null,
1010
'events' => $events,
1111
));

view/embed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
'room' => $room,
2929
'stream' => $stream,
3030

31-
'autoplay' => @$_GET['autoplay'],
31+
'autoplay' => isset($_GET['autoplay']) ? $_GET['autoplay'] : false,
3232
));

view/multiview.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
'title' => 'Stream-Übersicht',
66

77
'rooms' => $conference->getRooms(),
8-
'selection' => @$_GET['selection'],
8+
'selection' => isset($_GET['selection']) ? $_GET['selection'] : "",
99
));

0 commit comments

Comments
 (0)