如何在不使用php函数的情况下将变量从一个类传递到另一个类?

如何在不使用php函数的情况下将变量从一个类传递到另一个类?,php,function,parameters,Php,Function,Parameters,我有daoshistorial.php: <?php require "transferDao/daoTransferHistorial.php"; require "bdconnection.php"; class daoHistorial{ public function sqlSelect($tarea){ $aObjects=array(); $dbco

我有
daoshistorial.php

 <?php

require "transferDao/daoTransferHistorial.php";

require "bdconnection.php";


    class daoHistorial{

            public function sqlSelect($tarea){

                    $aObjects=array();


                    $dbconn = new DBconnection();
                    $db = $dbconn->bdConnection();
                    $stmt = $db->prepare("SELECT t1.tar_id, t1.rea_seccion, t1.rea_porcentaje, t1.rea_descripcion, t1.hrs_tarea, t1.tar_fechtermino 
                                          FROM act_registtarea t1
                                          inner join act_tarea t2
                                          ON t1.tar_id = t2.tar_id 
                                          where t2.tar_nombre = '$tarea'");
                    $stmt->execute();
                    $stmt->setFetchMode(PDO::FETCH_ASSOC);
                    $result = $stmt->fetchAll();

                    foreach ($result as $row) {
                            $aTransfer = new daoTransferHistorial();
                            $aTransfer->setPorcentaje($row['rea_porcentaje']);
                            $aTransfer->setDescripcion($row['rea_descripcion']);
                            $aTransfer->setFechaTermino($row['tar_fechtermino']);
                            $aTransfer->setSeccion($row['rea_seccion']);
                            $aTransfer->setHora($row['hrs_tarea']);

                            $aObjects[]=$aTransfer;
                    }

                    print_r($aObjects);
                    return $aObjects;
            }   
    }
?>
<?php

require "dao/daoHistorial.php";  

class HistorialTareas {

    public function getHistorial() {

        $aTransfer = new daoHistorial();

        foreach($aTransfer->sqlSelect() as $sKey=>$oValue){    
            $list[] = array('porcentaje' => $oValue->getPorcentaje(),
                            'descripcion' => $oValue->getDescripcion(),
                            'fecha_termino' => $oValue->getFechaTermino(),
                            'seccion' =>$oValue->getSeccion(),
                            'hora' =>$oValue->getHora()
                            );
        }
        print_r($list);
        return $list;
    }
}

?>
这里:
foreach($aTransfer->sqlSelect()as$sKey=>$oValue){
我有一个问题,就是缺少与的参数

sqlSelect()

我需要使用`daoshistorial.php中的
sqlSelect($tarea)

我知道我需要在
公共函数getHistorial($tarea)

但我需要这个:

public function getHistorial() {
$aTransfer = new daoHistorial();
foreach($aTransfer->sqlSelect($tarea) as $sKey=>$oValue){

因为之后我需要不带参数的
getHistorial()

将相关文件更新为以下内容:

daoshistorial.php

<?php
require "transferDao/daoTransferHistorial.php";
require "bdconnection.php";

class daoHistorial{
    public $tarea = NULL;

    public function setTarea($val) {
        $this->tarea = $val;
    }

    public function sqlSelect() {
        $aObjects=array();

        $dbconn = new DBconnection();
        $db = $dbconn->bdConnection();

        $incStatement = ($this->tarea != NULL) ? "where t2.tar_nombre = '.$this->tarea.'":"";

        $stmt = $db->prepare("SELECT t1.tar_id, t1.rea_seccion, t1.rea_porcentaje, t1.rea_descripcion, t1.hrs_tarea, t1.tar_fechtermino 
                                          FROM act_registtarea t1
                                          inner join act_tarea t2
                                          ON t1.tar_id = t2.tar_id 
                                          ".$incStatement);
        $stmt->execute();
        $stmt->setFetchMode(PDO::FETCH_ASSOC);
        $result = $stmt->fetchAll();

        foreach ($result as $row) {
                            $aTransfer = new daoTransferHistorial();
                            $aTransfer->setPorcentaje($row['rea_porcentaje']);
                            $aTransfer->setDescripcion($row['rea_descripcion']);
                            $aTransfer->setFechaTermino($row['tar_fechtermino']);
                            $aTransfer->setSeccion($row['rea_seccion']);
                            $aTransfer->setHora($row['hrs_tarea']);

                            $aObjects[]=$aTransfer;
         }

         print_r($aObjects);
         return $aObjects;
    }   
}
?>
<?php
require "dao/daoHistorial.php";  

class HistorialTareas extends daoHistorial {

    public function getHistorial() {

        foreach($this->sqlSelect() as $sKey=>$oValue){    
            $list[] = array('porcentaje' => $oValue->getPorcentaje(),
                            'descripcion' => $oValue->getDescripcion(),
                            'fecha_termino' => $oValue->getFechaTermino(),
                            'seccion' =>$oValue->getSeccion(),
                            'hora' =>$oValue->getHora()
                            );
        }
        print_r($list);
        return $list;
    }
}
?>

是否希望
sqlSelect
中的查询在不使用
WHERE
子句的情况下运行?因此,有时需要调用
getHistorial()
而不使用任何参数?因此,将
sqlSelect()
参数保留为空?嗨,我需要controllerisotrial.php:foreach($this->sqlSelect)中daohistional.php的相同变量$tarea($tarea)作为$sKey=>$oValue)。我想使用变量,getHisotrial()中没有,但我不知道如何传递变量和使用如果我不在getHistorialHi中传递参数,我对您的回答有这个问题:'daoHistorial::sqlSelect()缺少参数1',我需要ControllerHistorial.php中daoHistorial.php中的相同变量$tarea:foreach($this->sqlSelect($tarea)作为$sKey=>$oValue),对不起,我的英语我现在遇到了这个问题:语法错误,意外的“'from:$incStatement=($this->tarea!=NULL)”where t2.tar_nombre=”。$this->tarea.“:”“抱歉,请更新以下$incStatement=($this->tarea!=NULL)“where t2.tar_nombre=”。$this->tarea.”“:”;到$incStatement=($this->tarea!=NULL)?“where t2.tar_nombre=”。$this->tarea.”“;还更新了被遗忘者遇到的代码”?”
<?php
$historial = new HistorialTareas;
$getData = $historial->getHistorial();
<?php
$historial = new HistorialTareas;
$historial->setTarea('VALUE HERE');
$getData = $historial->getHistorial();