skip to Main Content

I have a PHP website running on Apache and PHP 7.1.
The application is running well on my PC, when I deploy to the server I get the following error:

PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\ (T_NS_SEPARATOR)

When I looked into the location the error is happening at, it was a PHP5.6+ syntax as I understood:

use function ...;

When I run php --version or which php it shows it is PHP 7.1.
Is there a setting that configures php to allow syntax above certain version?

EDIT:
phpinfo() is reporting PHP 5.5.9
I guess what I need is help on how to set Apache to use the default PHP version which is 7.1 in case of my server.

2

Answers


  1. Chosen as BEST ANSWER

    The answer is to disable the module PHP 5 and enable 7.1 for apache:

    sudo a2dismod php5
    sudo a2enmod php7.1
    sudo service apache2 restart
    

  2. use keywork will support all version of php. i think your function declaration error. 
    you can use below example and correct your function
    **use** can only be used with anonymous functions. Using it with named functions 
     gives a syntax error.
    
     <?
    function counter($start) {
      $value = $start;
    
     return function() use (&$value) {
       return $value++;
     };
    

    }

     $counter = counter(6);
    
    echo $counter() . "n";
    echo $counter() . "n";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search