Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Trying to access array offset on value of type null in isset
qoryto
post 9.01.2024, 12:43:23
Post #1





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 1.07.2009
Skąd: Rzeszów

Ostrzeżenie: (0%)
-----


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:

  1. protected static function getSentencesFromJSON($json)
  2. {
  3. $sentencesArray = json_decode($json, true);
  4. $sentences = "";
  5.  
  6. foreach ((array) $sentencesArray["sentences"] as $s) {
  7. $sentences .= isset($s["trans"]) ? $s["trans"] : '';
  8. }
  9.  


zmieniłem również linijkę na:
  1. foreach ((array) $sentencesArray["sentences"] as $s) {
  2. // $sentences .= isset($s["trans"]) ? $s["trans"] : null;
  3. $sentences = (isset($s['trans']) ? $s['trans'] : null); <--
  4.  
  5. }


Nieskutecznie :/

pozdrawiam

Ten post edytował qoryto 9.01.2024, 12:49:41
Go to the top of the page
+Quote Post
nospor
post 9.01.2024, 12:50:34
Post #2





Grupa: Moderatorzy
Postów: 36 457
Pomógł: 6297
Dołączył: 27.12.2004




$sentences .= ($s && isset($s["trans"])) ? $s["trans"] : '';


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Salvation
post 21.01.2024, 14:22:47
Post #3





Grupa: Zarejestrowani
Postów: 343
Pomógł: 70
Dołączył: 15.07.2014

Ostrzeżenie: (0%)
-----


W pełni wystarczy takie coś:
  1. $sentences .= $s["trans"] ?? '';


Ten post edytował Salvation 21.01.2024, 14:22:56
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 15:56