<?php
class appletree{
privated $catch;
piblic function tree($sweet){
$this->catch=$sweet;
return $this->catch;
}
$apple=new appletree();
$eat=$apple->tree('this apple is sweet');
echo $eat;
?>
再看一个抽象类:
//appletree.php:
<?php
abstract class appletree{
privated $catch;
abstract public function tree1($sweet);
public function tree2(){
echo'smell';
}
public function _construct(){
//......
}
}
?>
<?php
include_once('appletree.php');
class anothertree extends appletree{
public function tree1($sweet){
$this->catch='this apple is';
return $this->catch.$sweet;
}
}
$apple=new appletree();
echo $apple->tree1('sweet');
?>
<?php
interface fruit{
public function apple($sweet);
public function orange();
}
?>
<?php
include_once('fruit.php');
class fruittree implements fruit{
privated $catch;
public function apple($sweet){
$this->catch='this fruit is';
rerurn $this->catch.$sweet;
}
public function orange(){
return 'this orange is sweet';
}
}
$tree=new fruittree();
echo $tree->apple('sweet');
echo $tree->orange();
?>
<?php
interface TestInterface
{
const CONSTVAR = 'aaa';
static staticvar = 111;
public function alert($str);
}
class TestClass implements TestInterface
{
const CONSTVAR = 'bbb';
public function __CONSTRUCT()
{
echo TestInterface::CONSTVAR;
}
public function alert($str)
{
echo $str;
}
public function __DESTRUCT()
{
}
}
$test1 = new TestClass();
?>