Page 1 of 1
ParseError: syntax error, unexpected variable "$this", expecting ")"
Posted: Sat Sep 03, 2022 5:41 pm
by pm-netti
I'm having a strange problem that might be related to PHP 8:
Code: Select all
ParseError: syntax error, unexpected variable "$this", expecting ")" in C:\MAMP\htdocs\4011\extension\plugin\......\plugin.php on line 72
This is line 72:
Code: Select all
$myplugin = new Plugin(string $this->merchant, string $this->secret, array $header, string $body);
This rebukes those attributes. Why?
Ps. This message would have belonged to a different category, but I can't change it
-Peku-
Re: ParseError: syntax error, unexpected variable "$this", expecting ")"
Posted: Sat Sep 10, 2022 3:21 pm
by pm-netti
I don't think anyone has experience with Opencart 4 extensions?

Re: ParseError: syntax error, unexpected variable "$this", expecting ")"
Posted: Sat Sep 10, 2022 4:18 pm
by thekrotek
Try this:
$myplugin = new Plugin((string) $this->merchant, (string) $this->secret, (array) $header, (string) $body);
Re: ParseError: syntax error, unexpected variable "$this", expecting ")"
Posted: Sat Sep 10, 2022 6:21 pm
by pm-netti
thekrotek wrote: ↑Sat Sep 10, 2022 4:18 pm
Try this:
$myplugin = new Plugin((string) $this->merchant, (string) $this->secret, (array) $header, (string) $body);
Thank you!
Strange that Php 8.1 didn't recognize that code structure at this point.
Re: ParseError: syntax error, unexpected variable "$this", expecting ")"
Posted: Sun Sep 11, 2022 12:08 am
by JNeuhoff
You are dealing here with type-casting which require the brackets. This is different from a function declaration where the argument types are specified without brackets.
As regards OpenCart 4: There is no extension/plugin coming with it, it looks like you are talking about a 3rd party extension.
Anyway, OpenCart 4 isn't yet suitable for live websites, there still too many bugs to be fixed.