PHP Instanciation and late static binding context

2019-07-13 09:13发布

Short version

This code $out = new static(); makes PHP to quit unexpectedly and silently, using either xampp or wampserver in Windows.

Long version

I'm working on an old project which runs flawlessly on ubuntu 15.10 with NGinX/php-fpm php5.5.9 (dev) and also on Ubuntu 14.04 with apache2.4/Fast-CGI php5.5.13 (production).

Today, a designer colleague of mine just checked out this same repo to edit some html/css.
Unfortunately he hasn't been able to run the project using either Xampp:v3.2.2 (PHP 5.5.38) or Wampserver:2.5 (PHP 5.5.13) on his windows 10 desktop.

The code implements an old home brewed (active record like) database abstraction layer, in which all tables are represented with a class. Every class inherits from the Table class.
PHP stops on the following snippet (located in the "Table" class) :

# Table.php
public static function Get($id = null){
    echo 'test'; # Displays in the web browser
    error_log('test'); # append a line in the error_log file
    $out = new static(); # php seams to stop here
    echo 'after'; # Not displayed
    error_log('test'); # Not inserted in the log file
    // Fetch data from DB if id is specified
    if($id){
        $out->load($id);
    }
    return $out;
}

He then tried to replace the static call with:

// …
$class = get_called_class();
echo $class; # Displays "Article" (the right class name) in the browser
$out = new $class(); # The script dies silently as before.
// …

It looks like something is going wrong with PHP object instantiation in a late static binding context on windows.
Huge thank's to whom may help fix this.

0条回答
登录 后发表回答