【发布时间】:2012-11-05 14:53:45
【问题描述】:
我想指定可以赋予函数的数据类型。
在此演示代码(作为示例)中,我想指定给"__construct()" 函数的参数的数据类型,以便它只需要INT 用于$id 和Objects 的类型"example2" 为$some_object。
你知道我怎样才能做到这一点吗?
<?php
class example1{
private $id;
private $example2;
function __construct($id,$some_object){
$this->id = $id;
$this->object = $some_object;
}
function do_something(){
$this->example2->moep();
}
}
class example2{
public function moep(){
print("MOEP!!!");
}
}
?>
【问题讨论】: