http://bbs.17php.com/show_title.php?id=1443
解决方案 »
- Smarty报错 Call to a member function createTemplate() on a non-object
- 替换preg_replace.怎么老是【吃掉】前面的一个字符...
- php5在windows2003下连接MSSQL2000的问题
- 新人致敬贴
- ereg()返回的到底是什么类型?boolean?int?
- http和https的转化问题?
- windows2000/iis/php4/mysql问题
- 如何获取没有状态栏,工具栏,没有右键功能网页的代码?
- zend studio 9如何能远程访问虚拟空间上面的文件?并进行修改,保存
- PHPWord怎么对已有的表格进行赋值
- PHP6 require_once 的问题,在线等,急!!!!!
- PHP图片合成效果变很差该怎么解决
class Animal
{
//基类的属性
public $name; //名字 //基类的构造函数
public function __construct( $name )
{
$this->name = $name;
}
}//派生类
class Person extends Animal //Person类继承了Animal类
{
public $personSex; //性别
public $personAge; //年龄 //继承类的构造函数
function __construct( $personSex, $personAge )
{
parent::__construct( "heiyeluren" ); //使用parent调用了父类的构造函数
$this->personSex = $personSex;
$this->personAge = $personAge;
} function printPerson()
{
print( $this->name. " is " .$this->personSex. ",this year " .$this->personAge );
}
}//实例化Person对象
$personObject = new Person( "male", "");//执行打印
$personObject->printPerson(); //输出:heiyeluren is male,this year ?>
function __call($methodName,$methodArgs){
$newMethodName=$methodName.count($methodArgs);//这时候可以用参数个数/类型等判断
if (method_exists($this,$newMethodName)){
call_user_func_array(array($this,$newMethodName),$methodArgs);
}
}function x1($arg1){echo $arg1;}//实际上执行另外两个不同名的方法,来模拟
function x2($arg1,$arg2){echo $arg1.$arg2;}
}
$a=new a;
$a->x(1);//本来是不可能的,但是call的时候判断了,call内容要自己写
$a->x(1,2);
call在实例化后调用,构造函数就不行了,那就修改构造函数class b{
function __construct(){
$newMethodName=__CLASS__.func_num_args();//这时候可以用参数个数/类型等判断
$newMethodArgs=func_get_args();
if (method_exists($this,$newMethodName)){
call_user_func_array(array($this,$newMethodName),$newMethodArgs);
}
}function b1($arg1){echo $arg1;}//实际上执行另外两个不同名的方法,来模拟
function b2($arg1,$arg2){echo $arg1.$arg2;}
}$b=new b(1);
$b=new b(1,2);