0

在 PHP 5.2 服务器上,此代码可以工作,但在 5.6 下不再工作:

$value = $record->{self::TABLE_METHOD}();

在 5.6 下,我必须这样做:

$abc=self::TABLE_METHOD;
$value = $record->{$abc}();

否则,它可以通过变量使用“self::TABLE_METHOD”,但不能使用花括号。

任何有关为什么会发生这种情况的帮助将不胜感激!

根据要求,这是“真实”代码:

class TActiveRecordGateway extends TComponent
{
    private $_manager;
    private $_tables=array(); //table cache
    private $_meta=array(); //meta data cache.
    private $_commandBuilders=array();
    private $_currentRecord;

    /**
     * Constant name for specifying optional table name in TActiveRecord.
     */
    const TABLE_CONST='TABLE';
    /**
     * Method name for returning optional table name in in TActiveRecord
     */
    const TABLE_METHOD='table';

    /**
     * Record gateway constructor.
     * @param TActiveRecordManager $manager
     */
    public function __construct(TActiveRecordManager $manager)
    {
            $this->_manager=$manager;
    }

    /**
     * @return TActiveRecordManager record manager.
     */
    protected function getManager()
    {
            return $this->_manager;
    }
    /**
     * Gets the table name from the 'TABLE' constant of the active record
     * class if defined, otherwise use the class name as table name.
     * @param TActiveRecord active record instance
     * @return string table name for the given record class.
     */
    protected function getRecordTableName(TActiveRecord $record)
    {

            $class = new ReflectionClass($record);

            if($class->hasConstant(self::TABLE_CONST))
            {
                    $value = $class->getConstant(self::TABLE_CONST);
                    if(empty($value))
                            throw new TActiveRecordException('ar_invalid_tablename_property',
                                    get_class($record),self::TABLE_CONST);
                    return $value;
            }
            elseif ($class->hasMethod(self::TABLE_METHOD))
            {
                    $value = $record->{self::TABLE_METHOD}();
                    # THE PROBLEM HAPPENS HERE : $value is empty
4

0 回答 0