PHP 5.3 - unexpected [ [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I am trying to get a WordPress site working on a server running PHP 5.3. I am not able to update the server so am trying to make things compatible.
I am getting the following error...
Parse error: syntax error, unexpected '['
The line that is causing the error is...
echo wp_get_attachment_image($mysection['imageid'], 'medium', "", ["class" => "side_img"] );
Any ideas how to modify this code to be compatible?

The short array syntax was first introduced in PHP 5.4. PHP 5.3 does not understand what ["class" => "side_image"] is, hence the syntax error.
The solution is simple, change:
["class" => "side_image"]
into:
array("class" => "side_image")

PHP 5.3 does not support the "short array syntax" like [1, 2, 3, 4]. These must be converted to array(1,2,3,4).
See here: http://php.net/manual/en/migration54.new-features.php

Related

Syntax error while trying to use paymentwall example [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
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 ?
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

Parse Error with Wordpress Template - broke my site [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
Parse error: syntax error, unexpected '[' in
/home/content/90/12894990/html/wp-content/plugins/levelup-core/admin/metaboxes/config-meta-boxes.php
on line 261
I downloaded and opened the file in Dreamweaver and it's telling me there's actually a syntax error on line 521 which is:
'visible' => [$prefix . 'header_transparent', 'in', [1]]
can anyone help me with this? Cause it's made the entire wordpress site inaccessible, kinda driving me nuts.
You're probably using a PHP version before version 5.4, in which the short array syntax was added.
New features introduced include:
Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];.
To really solve this problem i need a bigger piece of code. But it seems like a wrong declaration of an array. In the line you posted replace the block quotes for proper quotation:
'visible' => $prefix . 'header_transparent', 'in', 1
Might not solve the entire problem, but its the best i can do with just this line.

PHP: xpath not working on php5.3 because of unexpected "[" [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I was running the following line on PHP5.4 without any problem:
$lstContent = $data->xpath("/response/lst[#name='highlighting']")[0]->lst[$i]->arr->str;
But now on PHP5.3 (production system) I get the following error:
Parse error: syntax error, unexpected '[' in /var/www/html/upload/inc_suche_code.php on line 153
Any ideas for a quick fix?
Updating PHP won't work for me.
In older versions of PHP you can not access array values directly on variables that are the result of a function. You have to split up the expression using a temporary variable.
$result = $data->xpath("/response/lst[#name='highlighting']");
$lstContent = $result[0]->lst[$i]->arr->str;
As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.
Source: http://php.net/manual/en/language.types.array.php
Edit: Obligatory "you should also consider upgrading your PHP version". This annoying limitation was fixed ages ago, not to mention that the 5.3 had its end of life in 2014, meaning it has not received security upgrades since.

Parse error: syntax error, unexpected '[' & functions_main.php on line 1114 [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Im installing my Wordpress theme and when I click activate I get the following error:
Parse error: syntax error, unexpected '[' in E:\Websites\HostingSpaces\mov1\movies.in\wwwroot\wp-content\themes\wp_mov\functions_main.php on line 1114
Anyone have any idea of how fix it?
This is caused by new-style array initialization ("short array syntax"), introduced in PHP 5.4:
<?php
$myArray = ["one", "two", "three"];
$myAssociativeArray = [
"key1" => "value1",
"key2" => "value2",
];
You'll have to upgrade to PHP 5.4 or better. If you let me know what OS you're using, I can provide specific instructions.
More info can be found in the array type manual.

PHP : Parse error, syntax error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
$router->addRoutes('', ['controller'=>'Home', 'action'=>'index']);
during compilation its generate an error
Parse error: syntax error, unexpected '['
Please help.
If is not >=5.4
PHP versions <= 5.4 do not support the [] syntax for array construction. Instead you shoud use array():
$router->addRoutes('',array('controller'=>'Home', 'action'=>'index'));

Categories