以下代码之前工作,但现在它抛出错误构造函数调用类 xyz 失败,我添加了有助于理解问题的代码。
代码:
public static function & Instance( $class )
{
static $loaded = array();
if ( !( isset( $loaded[ $class ] ) ) ) {
$c = SPLoader::loadClass( $class, false, null, false );
if ( !( strlen( $c ) ) ) {
$c = SPLoader::loadClass( $class, defined( 'SOBIPRO_ADM' ) );
}
if ( !( strlen( $c ) ) ) {
throw new SPException( SPLang::e( 'Cannot create instance of "%s". Class file does not exist', $class ) );
}
$loaded[ $class ] = $c;
}
$args = func_get_args();
unset( $args[ 0 ] );
try {
$obj = new ReflectionClass( $loaded[ $class ] );
$instance = $obj->newInstanceArgs( $args );
} catch ( LogicException $Exception ) {
throw new SPException( SPLang::e( 'Cannot create instance of "%s". Class file does not exist. Error %s', $class, $Exception->getMessage() ) );
} catch ( ReflectionException $Exception ) {
throw new SPException( SPLang::e( 'Cannot create instance of "%s". Class file does not exist. Error %s', $class, $Exception->getMessage() ) );
}
return $instance;
}
构造函数类:
class SPImexExportDownload
{
/**
* @var SPImexCtrl
*/
protected $proxy = null;
public function __construct( SPImexCtrl &$proxy )
{
$this->proxy =& $proxy;
}
public function data( $field )
{
$data = $field->getRaw();
$out = array();
try {
$data = SPConfig::unserialize( $data );
if ( count( $data ) ) {
// "{'label':'Nothing Special','protocol':'http','url':'radek.suski.eu'}"
if ( isset( $data[ 'label' ] ) && $data[ 'label' ] ) {
$out[ ] = $data[ 'label' ];
}
$out[ ] = $data[ 'protocol' ] . '://' . $data[ 'url' ];
}
}
catch ( SPException $x ) {
$this->proxy->log( $field->get( 'nid' ) . ": " . $x->getMessage(), 'error' );
$data = null;
}
return $out;
}
}
我的 PHP 版本:5.6