on my server (Centos5) i have PHP 5.2, i'm unable to update it, i read somewhere that PHP 5.4 won't work on Centos5, didn't inspect enough as i am in the middle of a lot of projects, anyways, here is the syntax :
$data['trees'] = (new Tree())->where('parent_id',0)->get();
On my WAMP it runs on PHP 5.4.3, on the server it gives me the following error:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR
Support for accessing instance members directly after a new expression was introduced in PHP 5.4 (finally). Note that the parentheses are required around the new expression, as in your given line of code, or it won't work.
I haven't heard of any particular server configurations or platforms where this won't work when running PHP 5.4. If it causes an error on a server where PHP 5.4 is installed, it's likely that's not the version that's interpreting your script (check your server config, .htaccess, and INI directives).
Related
Note: This is my first Symfony project, so obvious mistakes are possible.
I have just pushed my Symfony application from my local environment (where it works nicely) to a live server. Sadly, after running server:start, if I try and curl one of the local routes in the same way I tested on my local, I get the below error back:
FatalErrorException in Core.php line 1595: Parse Error: syntax error,
unexpected '.'
Note that the Core.php file is /var/www/symfony_playground/vendor/twig/twig/lib/Twig/Extension/Core.php
I didn't some searching online, and cannot see anyone else getting similar issues, so wonder whether I have a dependency issue (although I checked this).
The line in twig that is causing the issue looks like:
$ret = $object->$method(...$arguments);
Any suggestions much appreciated.
My guess is your server is not very up-to-date when it comes to PHP. Variadic functions (the ...$arguments) were introduced in PHP 5.6 so my guess is your server is running an older version than that.
Give it a debug with by echoing phpversion() or even the more detailed phpinfo().
If this is the case the only solution would be to update PHP as downgrading symfony doesn't really work.
I have some trouble when I upgrade PHP version 5.4 on my site. My site is built with CodeIgniter framework. It's working fine in previous version. When I check error log I see this error
error: cannot stat directory: (root_directory/project name/index.php/home)
Premature end of script headers: php54-cgi
cannot stat directory
It is linux error, not the PHP. In most common case after upgrading PHP you have changed user and/or group running php binary and new one simply does not have permissions to code directory.
So the answer will be - change user/group thats's running php.
I have just installed Laravel on my host following the official site's step by step guide and created an app called core, using the command
laravel new core
after seeing the success message I uploaded everything to my host, but when i try to access the /core/public folder from the browser i get 500 error on Chrome and nothing at all on firefox.
if i run the command
php artisan list
On SSH inside my core folder i get:
Status: 500 Internal Server Error
Content-type: text/html
Can anyone of you Laravel experts let me know please where did i go wrong?
thanks in advance
In the error log i found:
PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in ...public_html/laravel/core/public/index.php on line 50
even though i haven't touched any files, line 50 is:
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
I checked all the requirement from Laravel and my server meets them all
PHP >= 5.5.9
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
The application key was successfully generated inside .env
Also Directories within the storage and the bootstrap/cache directories are writable by the web server with permission 755
Unexpected class for Kernel::class implies to me that you are running a version of PHP lower than 5.5. Laravel only works for 5.5.9+.
My guess is your server provider claims to have PHP 5.5+ support, but the boxes may come with 5.4 installed on them. You will need to contact your server admin to get them to upgrade it if you cannot upgrade it yourself.
PHP 5.5 is required because the ::class syntax was added in that version.
Well, I'm transferring a little web server from one computer to other, on the 'other' computer I cannot a more updated version of PHP,
I just have to add my files through ssh and that's all, when I load my webpage it says explicitly:
The error is showing on a Debian with PHP 5.4.27 squeeze, the webserver comes from an Ubuntu with PHP 5.4.16 oneiric
Parse error: syntax error, unexpected '[' in ~directory~ on line 38
This is the line 38.
$VALUE=$DB->query("a nice sentence")->fetch()[0];
So, i was pretty surprised because PDO was accepted since PHP 5.1, so, i look deeper and i found the possible error, you can't simply do ->fetch()[0], you must separate it in order to be "processed",
However, I have transport this server with this information before, so i really don't know if it's something on the configuration of PHP or maybe the version by itself 5.4.X? You guys know any hint? As I said, i can't just install other updated version of PHP5, what do you recommend?
Have a nice night.
Edit: updated to the issue on the PHP 5.4 now
The error seems triggered by the array dereferencing. This was added in PHP 5.4.. Not sure how you made that work in 5.3.6
http://nl3.php.net/language.types.array.php
To workaround you could try
$VALUE = $DB->query("a nice sentence")->fetch();
echo $VALUE[0];
PHP Version on my ubuntu (where it works):
PHP Version 5.4.16
PHP Version on the Debian (where it does not work):
PHP Version 5.4.27-1~dotdeb.0
This version number was extracted by using phpinfo(); on the index page.
Apparently, the error was solved by JUST changing the first issue line (the other hundreds of codes that had that wasn't necessary to change, what i believe to be a little weird).
$VALUE = $DB->query("a nice sentence")->fetch()->offset(0);
I have:
on my pc:wamp server (apache+php-5.4.3+mysql)
on my vps:nginx+php5-fpm+mysql(all latest in the ubuntu 64 bit server repository).
recently I have reinstalled the whole vps
my problem is,
statement like this:
function foo($arr){
return $arr;
}
foo(['foo1','foo2','foo3'])
works on my pc, and used to work on the server (same installation) but now it gives
an error such as:
Parse error: syntax error, unexpected '[' in /home/Websites/Domains/squazza/php/db.php
on line 261
(replacing the [ ] with Array( ) does fix the problem)
now I assume that this problem is related to php.ini so i am asking what setting could possibly be affecting this kind of behavior and why?
If you look at the documentation that short syntax is only avaible in php 5.4+ I suspect your php versions are different.
This list of new features in PHP5.4 maybe of some use to you.
You're probably not using PHP 5.4. Run phpinfo() in your script and check it. And remember, you can have different PHP version in CLI mode.
As pointed out by #piddl0r, the short array syntax ([ 1, 2, 3 ]) was added in PHP 5.4. You'll note from The Ubuntu Package Archive that Ubuntu 12.04 - Precise Pangolin - only provided PHP 5.3.10; PHP 5.4.6 was provided in the next release, Quantal. To check your version of PHP, use phpinfo() or php --version on the command line.