2

I have been struggling with this for a few hours now. I am running CentOS 6.6. A few hours ago I was having issues with a Symfony project that required PHP 5.4+ because of some libraries required. So I installed version 5.4 and I used to have PHP 5.3.3.

PHP 5.4 allows some new features. Such as array shorthand declaration and binary data strings. Like this:

//array shorthand declaration
$arr = [1, 2, 3, 4]; //PHP +5.4

$arr = array(1, 2, 3, 4); //PHP 5.3.3

//binary data strings
0b001 //PHP +5.4

This is on the official documentation so here's a link to the source: https://secure.php.net/manual/en/migration54.new-features.php

However when executing those scripts I am getting errors as if I was not running PHP 5.4 for example I would get this one:

PHP Parse error:  syntax error, unexpected '[' in /vendor/wisembly/elephant.io/src/Engine/AbstractSocketIO.php on line 44

And the line of code would be:

//does not work
$data = [$event, $args]; //PHP 5.4 syntax

//it works
$data = array($event, $args); //PHP 5.3.3 syntax

This is the output of running php -v on the terminal

PHP 5.4.43 (cli) (built: Jul  8 2015 12:08:50)  
Copyright (c) 1997-2014 The PHP Group  
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

So based on this output I know I am running PHP version 5.4, the only thing that occurs to me is that somehow there is a configuration error somewhere and it is still using PHP 5.3.

So my question is how do I know what version of PHP is Symfony using? Thanks.

kittykittybangbang
  • 2,380
  • 4
  • 16
  • 27
Leo
  • 834
  • 8
  • 14
  • 1
    run `phpinfo()` on one of your pages and see what that gives you. its possible for you to have one version of php for the cli and one running from apache – castis Jul 17 '15 at 23:39
  • Just to "confirm" that it isn't a Symfony configuration, why don't you write a simple php with an array and try to execute it? – Mindastic Jul 17 '15 at 23:40
  • 1
    http://symfony.com/doc/current/reference/requirements.html says 5.3.9 – qooplmao Jul 17 '15 at 23:49

2 Answers2

4

When you run php -v, it show you the CLI's php version. Not the php version used for your script (run by your webserver).

You have multiple solutions to get the version used by your webserver.

Example with the function phpinfo(); in a .php page.

<?php
    phpinfo(); // Outputs information about PHP's configuration

Example directly from the command line (show you the same information displayed with an phpinfo())

php -i
zilongqiu
  • 846
  • 5
  • 12
2

You can use the command symfony console about, which displays the PHP version near the end:

E:\webfolder>symfony console about
 -------------------- ---------------------------------
  Symfony
 -------------------- ---------------------------------
  Version              5.1.2
  Long-Term Support    No
  End of maintenance   01/2021
  End of life          01/2021
 -------------------- ---------------------------------
  Kernel
 -------------------- ---------------------------------
  Type                 App\Kernel
  Environment          dev
  Debug                true
  Charset              UTF-8
  Cache directory      ./var/cache/dev (726 KiB)
  Log directory        ./var/log (0 B)
 -------------------- ---------------------------------
  PHP
 -------------------- ---------------------------------
  Version              7.4.0
  Architecture         64 bits
  Intl locale          fr_FR
  Timezone             UTC (2020-07-21T20:20:32+00:00)
  OPcache              false
  APCu                 false
  Xdebug               false
 -------------------- ---------------------------------
gpalex
  • 826
  • 1
  • 11
  • 27