PHP,传递范围的变量范围

时间:2013-10-11 10:24:57

标签: php symfony1

$columnToChange = $this->getColumnName($questionNo); //Gets EXAMHIST_Q2_JUGDGE
    $conn = Propel::getConnection(ExamHistoryPeer::DATABASE_NAME);
        //Update the approriate question with user answer in exam history table;
        $selectCriteria = new Criteria();   
        $selectCriteria->add(ExamHistoryPeer::EXAM_HISTORY_ID, $examHist->getExamHistoryId());
        $updateCriteria = new Criteria();   
        //This shows fatal error
        $updateCriteria->add(ExamHistoryPeer::$columnToChange, $userAnswer); 
        //$updateCriteria->add(ExamHistoryPeer::EXAMHIST_Q2_JUGDGE, $userAnswer); //This works
        BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);

致命错误:访问未声明的静态属性:ExamHistoryPeer :: $ columnToChange

你们中的任何人,请告诉我为什么这不能起作用,以及如何使其发挥作用 ExamHistoryPeer :: $ columnToChange

2 个答案:

答案 0 :(得分:1)

PHP认为您希望静态属性不是常量。这是因为$已登录ExamHistoryPeer::$columnToChange

而是使用constant('ExamHistoryPeer::columnToChange')来获取该常量的值。

答案 1 :(得分:0)

你可以这样做吗?

$oReflection = new ReflectionClass(ExamHistoryPeer);

//Value of the Constant
$mValue = $oReflection->getConstant($columnToChange);