The class Command
The class
command allows you to declare OOP classes in PHP.
You can also declare an anonymous class.
Syntax
class Test {
}
Example
Let's declare a class:
<?php
class User {
}
?>
Example
Let's declare an anonymous class:
<?php
$obj = new class {
public function sayHello() {
return 'Hello';
}
};
echo $obj->sayHello();
?>
Code execution result:
'Hello'
See Also
-
the
get_class
function,
which returns the name of the object's class -
the
instanceof
function,
which checks if an object belongs to a class