Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Hey I am trying to add a customize option in a wordpress theme that allows for the user to upload there own image in in a showcase but im getting a syntax error in my customize.php file. Can any one help me write this the correct way? thanks!
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/themes/wpbootstrap/inc/customizer.php on line 13
$wp_customize->add_setting('showcase_image', array(
'default' => get_bloginfo('template_directory').'/img/showcase.jpg', 'wpbootstrap'),
line 13 'type' => 'theme_mod'
));

Without spoon feeding the answer (as requested to #community above), but giving a re-usable technique to find these types of bugs ...
Temporarily reformat your code so all function paramters and/or array elements are on their own line and using identing appropriately. Eventually you'll likely see something that is not what you intended. Example below (you're almost there).
$wp_customize->add_setting(
'showcase_image', // func parm
array(
'default' => get_bloginfo(
'template_directory'
).'/img/showcase.jpg',
'wpbootstrap'
),
'type' => 'theme_mod'
)
);

Related

WordPress site with unending Parse Syntax Errors [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I am very new to coding - I was actually just trying to learn to edit an old website for a friend using WordPress, to make it more visually appealing and fresh.
Everything was way out of date, so I backed up the site, then started updating things in what I thought was the right order, but I was probably wrong since once I updated the plugins I got a Parse Syntax error and can't get into the wp-admin now.
I went through the steps in this tutorial (using FileZilla and Notepad++) to try and fix it, but it keeps giving me a new Parse Syntax error in the same file. Now I'm worried I'm just making things worse in there and I'm not certain what I should do.
The initial error was an unexpected "[" (or "]"? idr now...) on line 344, so I thought I needed to just get rid of it, but I don't think I was right. This is the error I have now, after trying to change things 2-3 times:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/67/14065667/html/wp-content/plugins/page-links-to/classes/plugin.php on line 346
Here is the section of coding I've been having issues in (lines 340-351):
public function enqueue_block_editor_assets() {
// Gutenberg.
if ( self::is_block_editor() && self::is_supported_post_type() ) {
wp_enqueue_script( 'plt-block-editor', $this->get_url() . 'dist/block-editor.js', array( 'wp-edit-post', 'wp-element', 'wp-plugins' ), self::CSS_JS_VERSION, true );
wp_localize_script( 'plt-block-editor', 'pltOptions',
'supports'
'newTab' => self::supports( 'new_tab' ),
],
]);
do_action( 'page_links_to_enqueue_block_editor_assets' );
}
}
What can I try to fix this?
Seems your argument list for wp_localize_script is malformed. It should be something like
wp_localize_script( string $handle, string $object_name, array $l10n )
Address that and you should be good. Without more context of what should belong to the $handle, $object_name and $l10n, can't fully type an answer to clear it up.
WP Localized Script Docs

PHP 5.3 - unexpected [ [duplicate]

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

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.

I'm writing in PHP for a church website, and keep getting a syntax error related to a string without any visible problems [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
The error is:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/svchapel/public_html/mmp_upgrade/administrator/components/com_sermonspeaker/s3/S3.php on line 1802
The line of code referenced is:
'code' => (string)$rest->response->body->Error->Code,
The line above the code referenced is:
$rest->response->error = array(
And the line below the code referenced is:
'message' => (string)$rest->response->body->Error->Message);
I can't find a problem in any of these lines... help?
Might be some odd, but invisible character there which ruins the PHP syntax (e.g., some sort of a fancy hyphen character instead of a regular one). I would try carefully re-typing the whole line manually in the plain text editor; if that doesn't help, I'd try to insert line breaks before each -> to see where exactly PHP borks up.

Categories