Class a{
  public function x(b $b){
     //do something;
  }
}
Class b{
   
}这样的传递可以么??

解决方案 »

  1.   

    php不是强类型, 怎么传都行
      

  2.   

    like this :  $GLOBALS['object']->method();
      

  3.   

    楼主说的是不是通过post,get传值
    如果是的话,传不了
      

  4.   

    看手册
    Type Hinting
    PHP 5 introduces Type Hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays (since PHP 5.1). Class a{
      public function x(b $b){
        $b->say();
      }
    }
    Class b{
      public function say()
      {
       echo "hello world!";
      }
    } class c{
      public function say()
      {
       echo "hello php!";
      }
    }
    $b = new b();
    $c = new c();
    a::x($b);//works!
    a::x($c);//Fatal error: Argument 1 passed to a::x() must be an instance of b