I am writing a PHP application and developing it localy (easyPHP). However, when I transfer my files on my server (FTP), i get on of the following error :
Parse error: syntax error, unexpected $end in /homez.93/dockydoc/_apps/dockydocs/include/functions.php on line xx
Error unexpected error function on line 1
Etc..;
When I re-download my PHP files and open them with Notepad++ or the classic windows pad, their are no more spaces, line break or tabulation in my file ! This result in the server not to be able to read PHP.
My files are UTF8 without BOM encoded (in Notepad++). I can't find the solution to this proble despite thorought search on the Internet... I anyone could help .. :)
Thanks,
Romain
Make sure you are using ASCII mode data connection when uploading the files over FTP. If you are set to binary, I believe this causes this!
Related
Recently I met a weird error and hope someone can help.
We use LiteSpeed WebServer and Nginx on top, with PHP 7.5 and MySQL 5 (well, WordPress is the framework). It runs well for many days.
Suddenly it goes fatal at this line in different files
include ("class-xxx.php");
The error log says
[02-Oct-2018 13:04:36 UTC] PHP Fatal error: require(): Failed opening required 'dlass-xxx.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear') in /xxx.php on line N
I double checked the code and see that the file name is declared "class-xxx.php", but somehow the server tries to include "dlass-xxx.php", thus it cannot find the file and trigger fatal error.
Solution? I re-upload the file, it works. But then it goes fatal in another file, at similar lines using include.
I notice that the first character in the file name, for example "c", is read incorrectly and shift 1 byte before (or after), so the file name is correct.
Such as
include "class-xxx.php" is parsed/read as "dclass-xxx.php"
include "page-xxx.php" is parsed"read as "opage-xxx.php"
...
this is very strange. Do anybody know the reason? Is it related to any caching/memory management of LiteSpeed or Nginx or PHP 7. ?
It happens on PHP 7. only because if I switch to PHP 5.6, the error does not happen.
Hope someone can help. Thanks a lot.
I've copied php and IIS files to new PC and can't bring it to work. Everytime getting this error:
Fatal error: Unknown: Failed opening required '-' (include_path:.;C:\PHP\includes)
So, what IS THIS -> '-'? My index.php just contain only two strings, it's <?php and phpinfo();
Some problems may occur when you use IIS under WIndows OS due to a misunderstanding of the file paths that contain non-Latin characters . Check the file path for the presence of non-Latin characters . Also try to change the encoding utf8 script - cp1251
For the information of anyone else who encounters this problem, I was attempting to use php 7.1 on Windows 10 and IIS using localhost.
I had only a test page containing a single phpinfo() command, but when I attempt to navigate to this page, I got:
Fatal error: Unknown: Failed opening required '-' (include_path='.;C:\php\pear') in Unknown on line 0
In my case, the handler mapping in iis was mis-configured.
Start IIS and under Double Click Handler mappings.
Select the entry for *.php and click Edit in the actions menu.
Change php.exe to php-cgi.exe as shown below.
You might also like to look at this page which explains things in a bit more detail:
http://php.net/manual/fa/install.windows.iis7.php
Regards.
Chris B.
I have various PHP files, none of which have been modified prior to the app working and it breaking. My problem is that for some reason, these files are suddenly throwing PHP parse errors for things like 'unexpected' square brackets in seemingly random places throughout the file, but upon manually checking the file, the syntax is correct.
The only thing I did that could have 'altered' the files would be various chmod operations to change the permissions. But how/why would this change the actual content of the files?
The files are called on boot just as they always have been, and have worked fine in the past, up until the recent chmod changes.
Is this permanent, or will I just have to restore my system from an earlier time?
RHEL 6.5, PHP 5.4.
Edit:
Example of the error:
PHP Parse error: syntax error, unexpected '[' in /var/ptc/CRM-dev/tools/init on line 122
What's on line 122:
$files = [];
Another example:
PHP Parse error: syntax error, unexpected '[', expecting ')' in /var/ptc/CRM-dev/vendor/react/promise/src/functions.php on line 68
What's on line 68:
return resolve([]);
But these files themselves haven't been changed (as far as I'm aware), and the syntax looks correct.
phpinfo() gives 5.4.39, which is the same as when running php -v on the server.
If the PHP version has been changed then it may be stumbling on the PHP 5.4 square bracket array syntax.
Use phpinfo(); to be sure that the PHP version running the web server is the same as the one you're using on the CLI.
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)
I have written a code to get images from instagram and saving data to DB using the code below:
Calling this PHP file from the command line, I am getting this error:
Warning: Unknown: Could not convert string to Unicode: 'No mapping for the Unicode character exists in the target multi-byte code page'.
PHP Fatal Error
This code is executing on Windows 7 64 bit. Please help me with this.
I have changed my pc's setting to english, now it is working