0

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).

3
  • 1
    imo that is 7.0.0+ code, so they technically have bug in their code, you should create pull request with removed bracket because they not have any purpose in that context. the developers most likely ran the code at higher php version, i can imagine that there was something like if(($var = ....)->...){ $var->... } meanwhile development process and then that var was no longer needed so it was removed but brackets stayed Commented Mar 5, 2023 at 7:32
  • @Kazz Thanks for your opinion; I changed the host PHP version to 7.4, and that part of the code (that errored) worked. The whole thing works now. So the rest-client install is just not compatible with PHP 5 even though its ReadMe says it is. Unfortunately, StackOverflow has mismarked this question as a duplicate, when there's no questions or answers that cover this particular error (about the -> 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. Commented Mar 5, 2023 at 20:54
  • yea i agree, you could post your case to the suggested duplicate post which leads here: stackoverflow.com/questions/3990212/… Commented Mar 5, 2023 at 21:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.