次のコードは以前は動作していましたが、今はxyzクラスのエラーコンストラクタ呼び出しが失敗しました。問題を理解するのに役立つコードを追加しました。phpのReflectionClassを使用してCunstructorの呼び出しに失敗しました
コード:
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
感謝。私はコンストラクタクラスと他のファイルのコードを追加しました、レビューしてください、私に教えてください、コンストラクタargsのrefは問題ですか? – Amit