drfu80954 2012-03-05 09:30
浏览 39
已采纳

参数在两个不同文件中的两个类之间传递

i want to ask how to pass parameter between two classes in two different files? ex:

class a{
  function aa(){
    $var1 = 10;
    return $var1;
  }
}
//in different file
class b{
  function bb(){
    echo"$var1"; //how this can be achieved?
  }
} 
  • 写回答

5条回答 默认 最新

  • dssnh86244 2012-03-05 09:38
    关注

    None of the answers here are right, since the op is asking to pass the parameter and not call it. The correct way to do it, is by creating an object of class b

    class a{
      function aa(){
        $var = 10;
        $obj_b = new b(); //create an object of the class b
        $b -> bb($var); //pass the $var value to bb method of class b
      }
    }
    
    //in different file
    class b{
      function bb($var){
        echo $var;  //now your values is passed here
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计