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


How return a value from one class function to another class function in PHP

如果一个条件从一个类函数到另一个类函数是真的,我正在尝试获取变量的值。

你能告诉我我该怎么做吗(我是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";
}

在这里你可以看到我需要从ErrorList类到Error$var1变量值。

提前谢谢。

问候特杰什·

<?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;
}
}
 ?>