class_alias in PHP

Syntax of class_alias

bool class_alias(string name, string alias)

Creates an alias to the class name. From then on, you can reference the class (for example, to instantiate objects) with either name or alias. Returns true if the alias could be created; if not, it returns false.

Example of class_alias


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);


Leave a Comment