Start a conversation

Incompatibility errors with PHP 7.0 after conversion

The only errors that may occur are due to codes used in events, libraries, and methods that are not compatible with PHP 7.0. These errors must be corrected manually.

1 - Short open tags

The short_open_tag directive tells PHP whether the abbreviated form (<? ?>) of the PHP opening tag is allowed.

Regardless of the php version, you need to check in php.ini if short_open_tags is enabled.

Solution 1:
Change the opening tag of php to (<?php ?>)
Solution 2:
Change the short_open_tags directive in php.ini:

short_open_tags = On

2 - New objects cannot be assigned by reference

The result of the new statement can no longer be assigned to a variable by reference:
class C {}
$c =& new C;

The example above will print in PHP 5:
           Deprecated: Assigning the return value of new by reference is deprecated in /tmp/test.php on line 3

The above example will print in PHP 7:
           Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php on line 3

           Remove reference (&) from assignment:

class C {}
$c = new C;

3 - PHP 4 Style Constructors

PHP 4 style constructors (methods that have the same name as the class where they are defined) are deprecated, and will be removed in the future. PHP 7 will issue E_DEPRECATED if a PHP 4 constructor is the only constructor defined in the class. Classes that implement the __construct () method are not affected.

class foo {
    function foo() {
        echo 'Eu sou um construtor';

The above example will print:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in example.php on line 3

4 - Static calls to non-static methods

Static calls to methods that have not been declared as static are deprecated, and can be removed in the future.

class foo {
    function bar() {
        echo 'Eu não sou estático!';



The above example will print:

Deprecated: Non-static method foo::bar() should not be called statically in - on line 8
I am not static!

For more information:

- PHP 7.0 new features
- PHP 7.0 deprecated features


Choose files or drag and drop files
Was this article helpful?
  1. Jefferson Albuquerque

  2. Posted
  3. Updated