Witam. Na php średnio się znam, więc proszę was drodzy forumowicze o pomoc.
Mam skrypt, który po przejściu na PHP 8.1 przestał działać.
wyskakuje błąd " Warning: Trying to access array offset on value of type null in /home/script.php on line 124"
Tutaj jak wygląda funkcja z linii 124:
protected http://www.php.net/static function getSentencesFromJSON($json) { $sentencesArray = json_decode($json, true); $sentences = ""; foreach ((http://www.php.net/array) $sentencesArray["sentences"] as $s) { $sentences .= http://www.php.net/isset($s["trans"]) ? $s["trans"] : ''; }
foreach ((http://www.php.net/array) $sentencesArray["sentences"] as $s) { // $sentences .= isset($s["trans"]) ? $s["trans"] : null; $sentences = (http://www.php.net/isset($s['trans']) ? $s['trans'] : null); <-- }
$sentences .= ($s && isset($s["trans"])) ? $s["trans"] : '';
W pełni wystarczy takie coś:
$sentences .= $s["trans"] ?? '';
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)