PHP Instanciation and late static binding context

 ̄綄美尐妖づ 提交于 2019-12-11 02:05:52

问题


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.

来源:https://stackoverflow.com/questions/40241094/php-instanciation-and-late-static-binding-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!