English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP tutorial

Advanced PHP tutorial

PHP & MySQL

PHP reference manual

PHP class_alias() function usage and example

PHP Class/Object function reference manual

The class_alias() function creates an alias for a class

Syntax

class_alias(string $original, string $alias[, bool $autoload = TRUE]);

Definition and usage

 Create an alias alias based on the user-defined class original. This alias class is completely the same as the original class.

Parameter

NumberParameters and descriptions
1

original (required)

Original class.

2

alias (required)

Class alias.

3

autoload (optional)

Whether to use automatic loading (autoload) if the original class has not been loaded.

Return value

Returns TRUE on success, or FALSE on failure.

Online example

The following is the usage of this function-

<?php
class foo { }
class_alias('foo', 'bar');
$a = new foo;
$b = new bar;
//Whether the objects are the same
var_dump($a == $b, $a === $b);
var_dump($a instanceof $b);
//Whether the class is the same
var_dump($a instanceof foo);
var_dump($a instanceof bar);
var_dump($b instanceof foo);
var_dump($b instanceof bar);
?>
Test and see ‹/›

Output result:

bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

PHP Class/Object function reference manual