構文例
<?php
header("Content-type: charset=UTF-8");
class Rectangle{
public static $counter = 0;
private $x=0,$y=0;
public function __construct($x,$y){
self::$counter ++;
$this->x = $x;
$this->y = $y;
}
public function getArea(){
return $this->x * $this->y;
}
public function getCounter(){
return self::$counter;
}
}
class Line{
private $x,$y;
public function __construct(){
if(func_num_args()===0){
$this->x = 0;
$this->y = 0;
}
else{
$this->x = func_get_arg(0);
$this->y = func_get_arg(1);
}
}
public function getPoints(){
return array("x"=>$this->x , "y"=>$this->y);
}
}
class NamedLine extends Line{
private $name = "default";
public function __construct(){
parent::__construct();
print func_num_args();
}
public function getName(){
return $this->name;
}
}
$rect = new Rectangle(10, 20);
print $rect->getArea() . "\n";
echo $rect->getCounter();
echo Rectangle::$counter;
$namedline = new NamedLine();
echo $namedline->getName();
echo $namedline->getPoints();
$array =$namedline->getPoints();
echo array_key_exists("x" , $array);
$x = $array["x"];
echo $x;
?>