This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Apologies for the undetailed description on my last question. I installed wordpress with Jevelin Theme on linux server, its a really basic setup, i had'nt edited any code whatsoever with the setup, or added any unecessary plugins, it was working straight out the box untill i have recently got this error:
Parse error: syntax error, unexpected '<' in
/tmp/theme_temp_setupgwHCl7 on line 2.
I have tried to do the following apon reading some other comments with the same problem:
Delete current theme (no effect)
Rename plugins folder (no effect)
I connot even access wp-admin upon deleting the theme. Get the same error. I cannot locate tmp/theme_temp on my server either. I see no such directory. Any help would be greatly appreciated. ------
I'll guess you've embedded html inside a block in the offending file (somewhere near the top).
You really need to provide a much more detailed problem description to get any real help.
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I am very new to PHP and am trying to modify an existing PHP file. Even when I only add an additional line and save the code, I receive an error on the website after uploading:
Parse error: syntax error, unexpected 'if' (T_IF) in /home/.../file.php on line 1
On line 1, the code starts with
<?php
When I only leave <? at the beginning, I get this error:
Parse error: syntax error, unexpected (T_VARIABLE) on line 1
At the end, there should not be any error, as I am not changing any single line of code.
When uploading the original file back on the server, the error disappears.
I am using XAMPP and PHPstorm with 7.3 interpreter.
In my case, it seemed to be something with the BOM encoding, as commented by DarkBee - Thanks!
I opened the file in Notepadd++, made my modification and set
Encoding -> Convert to UTF-8
before saving and it works.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 4 years ago.
I tried to set up a site from my old to new server, checked over the databases and set it up exactly like it should but it keeps throwing errors such as:
Parse error: syntax error, unexpected '?> ', expecting function (T_FUNCTION) in /search/index.php on line 2536
I can fix this by adding a } at the end of the page, but that wasn't needed for when it was on the other server and even after that there were more problems that followed up after:
Notice: Use of undefined constant SUBPAGE_LEVEL_1 - assumed 'SUBPAGE_LEVEL_1' in
would appear all over the site, I know the issue related to that is due to the constant not actually being defined on that particular page.
The main thing is I believe this is related to my php ini settings on the new server, these errors never appeared on the old server.
For reference my new server (the one with the errors) are on:
PHP 5.6.36-1+ubuntu18.04.1+deb.sury.org+1 (cli)
and the old server:
PHP 5.6.37 (cli)
I've looked up the differences between .36 to .37 but I've never noticed anything that stood out to me, is it because of this or am I overlooking something really obvious?
Update: error reporting is in a file called the config.php, it's not being loaded into the sitewide (as it did with the old server, I do know however it's being included because its the file that's required to make the site work)
Once I manually add the error report code into the header.php it fixes some but not all the issues and I feel I shouldn't have to touch any of the site code as it is.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I designed one website using Wordpress on localhost and I uploaded it to online server using filezilla, everything went success but after upload, i am facing problem, error code is give below....
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /home/u610435277/public_html/wp-content/themes/zerif-lite/inc/jetpack.php on line 1
php error
I cross checked my php code several times, it is correct. my code
Please give me sufficient information
May be you did not give a <?php at your file starting. That is why id did not expect function to begin there. Check it if this might be the problem.
I am diagnosing an issue with WP_cron(), so I wrote a very short app to list cron() tasks that are pending.
<? php
/*
Plugin Name: My WP-Cron Test
(there are more comments here but I left them out for brevity)
*/
function wpcron_print_tasks() {
echo '<pre>';
print_r( _get_cron_array() );
echo '</pre>';
}
?>
Attempting to activate this tiny plugin leads to the following:
Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in
/latamconnex/wp-content/plugins/my-wp-cron-test/my-wp-cron-test.php on
line 12
Line 12 triggers this according to the compiler, i.e. wpcron_print_tasks().
Somehow, even if this plugin only had a line with an echo command, it triggers the error.
Is there something basic I am missing about building a simple plugin?
Basically, I'd like to know what I need to know in order for even the simplest of plugins to activate.
System details: WordPress 4.7, PHP v. 7.0.13, deployed online with Pressable.com
Q1: Why is the error happening?
Let's look at what the error says. The message you get tells you what the problem is and where it's throwing the error. Let's break it down.
Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /latamconnex/wp-content/plugins/my-wp-cron-test/my-wp-cron-test.php on line 12
It's a "syntax error"
It's located in the file /latamconnex/wp-content/plugins/my-wp-cron-test/my-wp-cron-test.php
The error is thrown on line 12 of that file.
It's telling you there is a syntax error on or before line 12 of that file.
Looking at your code, line 1 has an error in it. Do you see it? You have <? php on line 1. PHP is not going to recognize that line as the opening PHP tag. Why? There's a space in between the ? and php.
Change that line to <?php. Notice, there's no space.
Make sure there are no other syntax errors between line 1 and 12.
Tip: Remove the Closing PHP Tag
You don't need the closing PHP tag ?> at the end of the file. I recommend removing the closing PHP tag.
Why? Any extra spaces or lines after that tag will cause the dreaded white screen of death. You can see the conversation about it here on Stack Overflow.
The best practice here is to omit the optional closing tag from all PHP files.
Q2:
Basically, I'd like to know what I need to know in order for even the simplest of plugins to activate.
First, WordPress has to recognize your code as a "plugin." Then once it finds it, then it's available for activation. There does not have to be a single line of code in the file for it to be activated.
How does WordPress recognize the plugin?
WordPress searches each folder in the wp-content/plugins folder. It's looking in the root of each folder for a bootstrap file.
What makes a file the "bootstrap?"
It's the file header (DocBlock) that identifies the plugin and makes it available to WordPress. That's your bootstrap file.
WordPress searches in the plugin folder's root for the file that has the properly structured file header.
The structure is defined in this Header Requirements document.
What should be in a plugin file?
All that's needed for the file to be activated is:
The opening PHP tag, i.e. <?php
The file's DocBlock
That's it. Now it's added to the list of plugins in Plugins > Installed Plugins (in the WordPress back-end admin).
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I downloaded php files through ftp. After editing them and uploading them again, I basically always get an error on line 1 with one of my first actions:
Parse error: syntax error, unexpected '{' in "...etc.
The weird thing is, they work correctly on my local host. They also display fine when I open them in my IDE (jetBrains phpStorm). However, if I open my files (from local host) in for example Notepad, the complete file is on one line.
Edit: Since my question was marked as a duplicate, i think i need to emphasise this: There is nothing wrong with the code itself. It works perfectly on my local host. I know what unexpected '{' means. The error i entered above is just an example. If the first line was an include(), i would get unexpected include etc. If i copy paste the exact code into a new file, the error is gone.
I did find out how to fix it for one file. If I simply copy the code in phpStorm, create a new file and paste it in there, it works. However, there are around 500 files, so doing this manually would take a lot of time. So my questions are:
What causes this kind of behaviour and how can i prevent this in the future.
How can i fix this for my current project.
Check the type of end-of-line / newline character being inserted by your IDE.
I had a similar problem with Notepad++, and the setting to change was: Edit >> EOL Conversion >> (and in my case I has to set it to Windows Format)