class Another extends Something { var $y; function setY($v) { // Methods start in lowercase then use lowercase to seperate // words in the method name example getValueOfArea() $this->y=$v; }
$obj=new Something(); // x=3 and y=5 $obj=new Something(8); // x=8 and y=5 $obj=new Something(8,9); // x=8 and y=9 缺省参数的定义方法和 C++ 一样,因此你不能传一个值给 Y 但让 X 取缺省值,实参的传递是从左到右,当没有更多的实参时函数将使用缺省参数。
class Myclass { function Myclass() { $name="Myclass".func_num_args(); $this->$name(); //Note that $this->$name() is usually wrong but here //$name is a string with the name of the method to call. }
function Myclass1($x) { code; } function Myclass2($x,$y) { code; } }