如何在PHP中将值从一个类函数返回到另一个类函数

时间:2014-08-25 04:23:06

标签: php

如果条件从一个类函数转到另一个类函数,我试图获取一个varibale的值。

请你告诉我我该怎么做(我是PHP新手。)

代码:

class ErrorList{
static function getErrorsSince($delay, $criteria = NULL) {
        global $appsFeXref, $table_error,$table_error_dis, $table_occurrence, $table_status, $table_fe_parameters, $debugMode;

        if ($criteria->isValid()){
            $var1 = '123';
         }
}

Class  Error{

             function initFromDb($initDetails = false) {
        global $appsFeXref, $table_error, $table_status, $table_fe_parameters, $table_error_dis;
        $details = ($initDetails)? ", s.last_time, s.last_time_origin, s.last_time_machine, s.last_time_text, s.last_time_peak, ed.comment ":"";
        $test = $var1;
         echo "$test";

}

在这里,您可以看到我需要从$var1班级到ErrorList班级的Error变量值。

提前致谢。

此致 Tejesh.B

1 个答案:

答案 0 :(得分:0)

<?php 
class ErrorList{
static function getErrorsSince($delay, $criteria = NULL) {
        global $appsFeXref, $table_error,$table_error_dis, $table_occurrence, $table_status, $table_fe_parameters, $debugMode;

        if ($criteria->isValid()){
            $var1 = '123';
            return $var1;
         }
}
}
class  Error{

             function initFromDb($initDetails = false) {
        global $appsFeXref, $table_error, $table_status, $table_fe_parameters, $table_error_dis;
        $details = ($initDetails)? ", s.last_time, s.last_time_origin, s.last_time_machine, s.last_time_text, s.last_time_peak, ed.comment ":"";
      $call_class = new ErrorList();
      $get_val = $call_class->getErrorsSince();
        $test = $get_val;
         echo $test;

}
}

 ?>