I'm trying to plug in a major payment gateway for a merchant, and running into a strange error based on running their sample code (which I'm trying because nothing else they've recommended is working).
I admit I've never seen this syntax before, and the code may be some sort of FrankenMonster at this point. I already searched for the error on Google and in StackOverflow, but none that I found are the same situation as this one.
EDIT: StackOverflow now shows that the question has already been answered in a list of 20 questions that don't cover this specific error (which I was forced to specify in the title about the -> operator-specific error). StackOverflow's AI mind is just wrong, and I discovered the answer based on a comment below. No way to fix the inaccurate forced blurb on my question, sorry. I'll leave my own answer for this since it's a unique issue here.
Here's the full error:
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /Users/Me/Sites/cybersource-rest-samples-php/vendor/cybersource/rest-client-php/lib/ApiClient.php on line 338
Tracing it, I couldn't figure out what I was looking at, or why it was wrong...
The line in question:
// debugging for curl
if (($this->merchantConfig->getLogConfiguration())->isLoggingEnabled()) {
So, the issue seems to be parentheses wrapping $this->merchantConfig->getLogConfiguration() are causing the parsing engine to think that the (supposedly) returned object is not going to be an object, so that the operator -> is just bad syntax. Intuitively I'd think the parentheses would just be harmless extraneous encapsulators (though it's making my brain squirm thinking about it), and the object returned within them would still apply to the operator... maybe the coder was using a different version of PHP where this was valid syntax? I can't tell.
The code is written in PHP 5.6, supposedly, according to CyberSource's docs:
https://github.com/CyberSource/cybersource-rest-client-php
My host is running PHP 5.6 as well, so that's not the problem.
I could try and fix it in a fork of the repo, but I'm curious what some other eyeballs will see, as I'm not even finding PHP documentation for functionality like this (which of course make sense with a syntax error).
if(($var = ....)->...){ $var->... }meanwhile development process and then that var was no longer needed so it was removed but brackets stayed->operator syntax for the object in parentheses), so I'm hoping they'll re-open it so I can leave the actual answer. The PHP parser was correct: It's a syntax error... but for PHP 5, not 7.