-2

Syntax error while using this code , An example from paymentwall

    $widget = new Paymentwall_Widget(
        ''. $_SESSION['PLR_ACCOUNT']['PLR_ID'] .'', 
        'p10_1', 
        array(
            new Paymentwall_Product(
                'product2',                        
                9.99,                                   
                'USD',                                  
                'Elite 3 months',                      
                Paymentwall_Product::TYPE_SUBSCRIPTION, 
                1,                                      
                Paymentwall_Product::PERIOD_TYPE_MONTH,
                true                                  
            ),
            array(
                'email' => 'user@hostname.com', 
                'history[registration_date]' => 'registered_date_of_user',
                'ps' => 'all'
            )
            echo $widget->getUrl();
        )
}

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ')' in C:\Users\Arlindi\Desktop\X-Portal - V2.6.8 - FINAL\test-server\root\pages\premium_info.php on line 301

Line 301 is

echo $widget->getUrl();

How to solve it ?

M4HdYaR
  • 1,124
  • 11
  • 27
  • When you see a parse error it can often be helpful to look at the statement right _before_ the one that's identified. Is the statement before `echo $widget->getUrl()` properly terminated with a `;`? (Since `echo` is the thing that's unexpected we know that PHP is expecting something else in its place.) – ChrisGPT was on strike Aug 15 '18 at 20:14
  • I tried to read there but nothing! I am newbie and trying everything to fix it – Eskimo Cnr Aug 15 '18 at 20:15
  • yes i already added getUrl(); – Eskimo Cnr Aug 15 '18 at 20:15
  • I'm suggesting that you look at the code _before_ that line. Your indentation makes it hard to read, but I think it starts at `$widget = new Paymentwall_Widget(` and continues all the way to line 300. Does that whole chunk of code look correct? – ChrisGPT was on strike Aug 15 '18 at 20:16
  • You didn't close your `$widget` declaration. Using a good IDE/Editor with syntax checking and highlighting will help you catch a lot of the parse/syntax errors. – aynber Aug 15 '18 at 20:17
  • can you suggest me any ide editor free that check syntax ? – Eskimo Cnr Aug 15 '18 at 20:20
  • Fixed your code for you, should be fairly obvious the problem now. I suggest you try to keep your code formatted well. – GrumpyCrouton Aug 15 '18 at 20:28
  • still not working!!! – Eskimo Cnr Aug 15 '18 at 20:34

1 Answers1

0

Look at your code context!

When you get syntax error it means you have typo or your code is somehow wrong as in PHP parse/syntax errors; and how to solve them? explained when you see syntax error,

Always look at the code context. The syntax mistake often hides in the mentioned or in previous code lines. Compare your code against syntax examples from the manual.

In your example you used echo in your function argument and after array(...) It is not right in php

function(array(...)echo something;) is not correct syntax in php

As you didn't say what you want your code actually do, I don't know what can be your correct code but I guess you should close Paymentwall_Widget() parentheses before echo and put one semicolon after the parentheses before echo line

Community
  • 1
  • 1
M4HdYaR
  • 1,124
  • 11
  • 27