opencart / opencart-3

OpenCart 3.x
Other
25 stars 32 forks source link

3 type errors and an unknown #292

Closed danielw1990 closed 1 week ago

danielw1990 commented 1 week ago

My PHP knowledge is quite outdated, but here is my understanding of the problem: tried to run Opencart3 with PHP8.3 3 type errors upload/system/framework.php:108

PHP is now more type strict and does not like the empty values interpreted as "null" (explicitly cast the 3 ssl strings with "(string)")

Okay, so far so easy, just cast them to string, seems to work.

The unknown

But this I don't quite understand:

 public function get(string $key): string {

                 return $this->data[$key] ?? $key;
          }

it throws a type error because it expects a string and not an array.

some steps later... I know this no solution. Because as stated: quite frankly I have no idea what this line does. (or my understanding conflicts with the fact it broke). But now everything seems to work except for localization, so technically still progress.


         public function get(string $key): string {
                 //echo "Key: ".$key."\n";

                 $ret = $this->data[$key] ?? $key;
                 //print_r($ret);
                 return $key;
                 //return $this->data[$key] ?? $key;
          }

Left in the traces of my search effort.

danielw1990 commented 1 week ago
                 if(isset($this->data[$key]) and is_string($this->data[$key]))
                 {
                         $ret = $this->data[$key];

                 }else{
                         $ret = $key;
                 }

                return $ret;

While I still apparently don't fully understand the ?? operator or why it breaks here. This replacement seems to work.

TheCartpenter commented 1 week ago

If it breaks with ??, then you are not properly using the PHP 8.3x releases on your server.