类常量
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
?>
