PHP Interview questions

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

Define inheritance and how it can be implemented in PHP?

A class can be inherited methods and properties of another class by using keyword extends in the class declaration and it is not possible to extend multiple classes; a class can only inherit from other base class.

The inherited methods and properties can be overridden by redeclaring them with the same name defined in the parent class. However, if a parent class has defined a method as final, that method can not be overridden. It is possible to access the overridden methods or static properties by referencing them with parent::.

When overriding methods, the parameter signature should remains same or PHP will generate an E_STRICT level error. This does’nt apply to a constructor, which allows overriding with different parameters.


class ExtendClass1 extends SimpleClass1
   // Redefine the parent method
   function displayVar()
      echo "Slightbook\n";

$extended = new ExtendClass1();


Next 5 interview question(s)

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?
What is the difference between var_dump() vs print_r()?