0
以下代碼工作較早,但現在它的投擲錯誤構造函數調用類xyz失敗,我已經添加了有助於理解問題的代碼。Cunstructor調用失敗使用ReflectionClass在php
代碼:
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
感謝您的回覆。我添加了更多的構造函數類和其他文件的代碼,請檢查並讓我知道,參考構造函數參數是一個問題? – Amit