PHP Interview questions

Total available count: 33
Subject - PHP Frameworks
Subsubject - PHP

What is the use of ::class?

Since PHP 5.5, the class keyword is also used for the class name resolution. You can get a string containing the fully qualified name of the ClassNames class by using ClassNames::class. This is particularly useful with namespaced classes.


namespace NS {
class ClassNames {

echo ClassNames::class;
The Output: NS\ClassNames

Note: Class name resolution using by ‘::class is a compile time transformation. That means at the time the class name string is created no autoloading has happened yet. As a consequence, class names are expanded even if the class does not exist. No error displays in that case.

Next 5 interview question(s)

Define inheritance and how it can be implemented in PHP?
What are Objects?
What are Classes?
What is an operator and how many types of operators are there?
What is the difference between named functions vs anonymous functions?