php5类的类型提示
span style=font-family:Verdana, sans-serif, 宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;php面相对象中参数变量可以包含任何基本类型的数据,参数默认情况下也可以包含任何类型的对象,这中灵
php面相对象中参数变量可以包含任何基本类型的数据,参数默认情况下也可以包含任何类型的对象,这中灵活的运用在在方法定义中可能会出现问题,但是php引入类的类型提示
class productwrite
{
public function write(product $product) // 规定必须是product的实例
{
$str = "{$product->title}".
$product->getproducter().
"({$product->price})\n";
print $str;
}
}
class product
{
public $title;
public $b;
public $c;
public $price;
function __construct($title,$b,$c,$price)
{
$this->title = $title;
$this->b = $b;
$this->c = $c;
$this->price = $price;
}
function getproducter()
{
echo $this->b." ";
echo $this->c;
}
}
$product = new product("my antonia","willa","cather","5.99");
$write = new productwrite();
$write->write($product); //把product的实例传入 productwrit的write方法中
- 上一篇:创建和删除目录或者文件
- 下一篇:英雄联盟资料库
精彩图集
精彩文章






