0

I am facing after an issue after upgrading version magneto 2.4.2 to 2.4.5 When I run this command I got error

json_decode(): Passing null to parameter #1 ($json) of type string is deprecated

app/code/Vendor/Module/Helper/Data.php(495): json_decode(NULL)

2 Answers 2

0

Try below code 1. Add string (string)

public function getParametersAttribute()
{
   return $cookieValue=json_decode((string)$cookieValue);
}

2. Add condition

public function getParametersAttribute(){
if (isset($cookieValue)) {
   return $cookieValue=json_decode($cookieValue);
 }else{
    return [];
  }
}

3. Try this one

public function getParametersAttribute(){
   return $cookieValue= json_decode($cookieValue ?? '');
}
0

app/code/Vendor/Module/Helper/Data.php

**Additional context**

Try to use null coleascing operator:

public function getParametersAttribute()
{
   -. return $cookieValue=json_decode($cookieValue);
}

public function getParametersAttribute()
{
   +. return $cookieValue= json_decode($cookieValue ?? '');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.