在看php5的时候看到上介绍PHP5有个新特性:对象类型提示。
函数声明中可以对参数进行对象类型提示。就写了下面一个程序:
<?php
class b
{
function add (Integer $a,Integer $c)
{
return ($a+$c);
}
}
$obj = new b();
$d =$obj->add(1,1);
echo $d;
?>
结果提示
Catchable fatal error: Argument 1 passed to b::add() must be an instance of Integer, integer given, called in C:\xampp\htdocs\StudyPHP\clone.php on line 10
新手大家帮看看,我想问下这里PHP整型该怎么指定?
函数声明中可以对参数进行对象类型提示。就写了下面一个程序:
<?php
class b
{
function add (Integer $a,Integer $c)
{
return ($a+$c);
}
}
$obj = new b();
$d =$obj->add(1,1);
echo $d;
?>
结果提示
Catchable fatal error: Argument 1 passed to b::add() must be an instance of Integer, integer given, called in C:\xampp\htdocs\StudyPHP\clone.php on line 10
新手大家帮看看,我想问下这里PHP整型该怎么指定?
class b
{
function add (a $a,a $c)
{
return ($a->n+$c->n);
}
}
class a
{
public $n;
function __construct($n)
{
$this->n = $n;
}
}$obj = new b();
$a = new a(1);
$c = new a(2);
$d = $obj->add($a,$c);
echo $d;