Unexpected T_STRING in PHPWebSocket - php

I was trying to test some HTML5 WebSockets using phpwebsocket, but I got an error while trying to execute the server script:
Nathan-Campos-MacBook-Pro:socket Nathan$ php -q server.php
Parse error: syntax error, unexpected T_STRING in /Applications/XAMPP/xamppfiles/htdocs/socket/server.php on line 109
Nathan-Campos-MacBook-Pro:socket Nathan$
What I should make to correct the error?
I'm using PHP 5.3.3 and here is the content of line 109:
socket_close($user->socket);

I got the same problem. this is How I solve it. copy all the code in server.php and paste it in Eclipse in which you create a untitle php file. then you can inspect the line 109, where there are three extra dots, remove them and update what you have. i am sure this will solve it.

I think it's the format problem when you copy the server.php code. first time, I copy the code from Editor Panel, this problem was occured. so I had make a new copy from here, and successed to run the server.php :)

Related

php application fail with Apache server (Wordpress, phpMyAdmin and Squirrrelmail)

Yesterday my Apache installation stopped working with PHP applications like Wordpress, phpMyAdmin and Squirrelmail.
The problem is that Apache-php chokes on lines containing the "global" statement.
The Wordpress error looks like this:
PHP Parse error: syntax error, unexpected '$error' (T_VARIABLE) in /var/www/html/XXXXXXX/wordpress/wp-login.php on line 34
Line 34 contains the "global" statement:
global $error, $interim_login, $action;
Similar in phpMyAdmin:
PHP Parse error: syntax error, unexpected '$text_domains' (T_VARIABLE) in /usr/share/php/gettext/gettext.inc on line 47
Line 47 also includes the global statement:
global $text_domains, $default_domain, $LC_CATEGORIES, $EMULATEGETTEXT, $CURRENTLOCALE;
If I comment out the line PHP just fails on the next line including the "globa"l statement.
I tried to execute the file using php command line and it finishes without any error.
The latest software upgrades doesn't seem to be related.
iwl100-firmware
iwl1000-firmware
iwl105-firmware
iwl135-firmware
iwl2000-firmware
iwl2030-firmware
iwl3160-firmware
iwl3945-firmware
iwl4965-firmware
iwl5000-firmware
iwl5150-firmware
iwl6000-firmware
iwl6000g2a-firmware
iwl6000g2b-firmware
iwl6050-firmware
iwl7260-firmware
libappstream-glib
libertas-usb8388-firmware
linux-firmware
opus
rpcbind
tzdata
tzdata-java
webkitgtk4
webkitgtk4-jsc
webkitgtk4-plugin-process-gtk2
Hoping that someone has a clue.
Thanks
John

Sudden PHP parse error on RHEL

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.

PHP adding value to array

In PHP why is this a syntax error:
$row['some_key'] = "kkkk";
Raises
Parse error: syntax error, unexpected T_STRING
From the documentation I understood this to be perfectly valid PHP, yet it throws the same error every time (and the error of course goes away then I comment the line out).
Edit: After long searching I actually noticed that the file is indeed corrupted in some way. In Vim (on ubuntu 12.04) the file looks just normal. But when viewing from other computers it's corrupted. So not related to PHP.
In PHP why is this a syntax error:
It's not. If you're getting unexpected T_STRING, the problem is elsewhere (hint: look at the line above).

Tabs, line breaks encoding when uploading PHP files on my server

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!

Unexpected T_STRING. how to reroute a new subdirectory with php

This is probably a simple fix. Basically, when trying to reroute a wordpress subdirectory the file contents I've moved is unable to 'open stream' for the directory, showing;
Fatal error: require() [function.require]: Failed opening required './shop/wp-blog-header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/jackpier/public_html/onemilehigh.co.uk/shop/index.php on line 17
So, I've been trying to include the (include_path='.:/usr/lib/php:/usr/local/lib/php') into my index.php, but am then showed-
Parse error: syntax error, unexpected T_STRING in /home/jackpier/public_html/onemilehigh.co.uk/shop/index.php on line 17
I must be integrating it incorrectly but don't know in what way.
I am really inexperienced with php
Here's my current code:
/** Loads the WordPress Environment and Template */
require('./shop/wp-blog-header.php'); path='.:/usr/lib/php:/usr/local/lib/php');
Again, probably really simple.
You have a syntax error:
require('./shop/wp-blog-header.php'); path='.:/usr/lib/php:/usr/local/lib/php');
^^^^ a 'constant'
What you're attempting to do doesn't work in PHP. If you're trying to change the include path, that's done via ini_set('include_path', ...), and must be done BEFORE you try to include/require a file. You do not do this by dumping some random junk onto the same line as an require directive.
path='.:/usr/lib/php:/usr/local/lib/php');
should be
path='.:/usr/lib/php:/usr/local/lib/php';
You had an extra )
Edit
And also read what Marc said in his answer and his comment on this one.

Categories