background image

public

 

function

 b(); 


任何实现接口的类都要实现接口中定义的所有方法,否则就必须是抽象类. 
类在声明中使用

implements

来实现某个接口. 

class

 Shop 

implements

 a{ 

public

 

function

 b(){ 

... 


 
9> 

 

异常 exception 

PHP5

 

引入异常类

 
10>

 

拦截器 interceptor 

__get(

$property

); 

 

访问未定义的属性时被调用

__set(

$property

,

$value

); 

 

给未定义的属性赋值时被调用

__isset(

$property

); 对未定义的属性使用 isset()时被调用; 

__unset(

$property

);对未定义的属性调用 unset()时被调用; 

__call(

$method

$arg_array

); 

 

调用未定义的方法时候被调用

例: __get()

 

的实现

代码如下:
 

function

 __get(

$property

){ 

$method

="get{$property}"; 

if

(method_exists(

$this

,

$method

)){ 

return

 

$this

->

$method

(); 



 

function

 getName(){ 

return

 "Bob";} 

 

function

 __isset(

$property

){ 

$method

="get{$porperty}"; 

return

(method_exists(

$this

$method

)); 


 

function

 __set(

$property

$value

){ 

$method

="set{$property}"; 

if

( method_exists(

$this

,

$method

)){ 

return

 

$this

->

$method

(

$value

);