class_alias

基本介紹

  • 名稱:class_alias
  • 返回值:成功時返回 TRUE, 或者在失敗時返回 FALSE.
簡介,說明,參數,返回值,範例,

簡介

(PHP 5 >= 5.3.0)
class_alias — Creates an alias for a class

說明

bool class_alias ([ string $original [, string $alias ]] )
Creates an alias named alias based on the defined class original. The aliased class is exactly the same as the original class.

參數

original
The original class.
alias
The alias name for the class.

返回值

成功時返回 TRUE, 或者在失敗時返回 FALSE.

範例

Example #1 class_alias() example
<?php
class foo { }
class_alias('foo', 'bar');
$a = new foo;
$b = new bar;
// the objects are the same
var_dump($a == $b, $a === $b);
var_dump($a instanceof $b);
// the classes are the same
var_dump($a instanceof foo);
var_dump($a instanceof bar);
var_dump($b instanceof foo);
var_dump($b instanceof bar);
?>
以上例程會輸出:
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
參見
get_parent_class() - 返回對象或類的父類名
is_subclass_of() - 如果此對象是該類的子類,則返回 TRUE
PHP class_alias note #1
Something to note,
If the $original class has not yet been defined or loaded, the auto loader will be invoked in order to try and load it.
If the class for which you are trying to create an alias does not exist, or can not be loaded with the auto loader, you will generate a PHP Warning.

相關詞條

熱門詞條

聯絡我們