PHP 类的重构思路
引申:http://fengxiaohua1.bokee.com/viewdiary.13001675.html
在上文中看到 Come on! 的关于类的重建问题的解决办法,很受启发,因为之前没自己写过类,就那上面的东西小测试了下.
<?php
class ValidateNumber{
......
......
function ValidateNumber(){
$name="ValidateNumber".func_num_args();
$this->$name();
}
function ValidateNumber0(){}
function ValidateNumber2($para1,$para2){
......
......
}
......
......
}
?>
结果发现, Come on! 的方法中, 第七行代码 就是 可变函数 的调用会出现 参数丢失的警告.
Come on! 的思路很牛X 怕自己以后忘掉,于是 把小 Bug 修复如下:
<?php
Class test
{
var $info;
function test()
{
$num = func_num_args();
$name="test" . $num ;
if( $num)
return $this->$name( func_get_args() );
return $this->$name();
}
function test0()
{
$this->info="args:0";
return $this;
}
function test1( $args )
{
$this->info = $args ;
return $this;
}
function show()
{
echo "this->info = ".$this->info;
}
}
?>
页:
[1]