正 文

PHP5.0对象模型探索之其它特性


www.7dspace.com  更新日期:2005-11-30 1:07:30  七度空间


  类常量

  PHP5中可以使用const关键字来定义类常量。

<?php
class Foo {
 const constant = "constant";
}

echo "Foo::constant = " . Foo::constant . "\n";
?>

  __METHOD__常量

  __METHOD__ 是PHP5中新增的“魔术”常量,表示类方法的名称。

  魔术常量是一种PHP预定义常量,它的值可以是变化的,PHP中的其它已经存在的魔术常量有__LINE__、__FILE__、__FUNCTION__、__CLASS__等。

<?php
class Foo {
 function show() {
  echo __METHOD__;
 }
}

class Bar extends Foo {}

Foo::show(); // outputs Foo::show
Bar::show(); // outputs Foo::show either since __METHOD__ is
// compile-time evaluated token

function test() {
 echo __METHOD__;
}

test(); // outputs test
?>

3页,页码:[1] [2] [3] 

上一篇:PHP5.0对象模型探索之Zend引擎的发展
下一篇:PHP5.0对象模型探索之抽象方法和抽象类
作者:haohappy2004  来源:blog ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐