PHP (Core & OOP)
Fundamental PHP structures, Object-Oriented patterns, traits, and interface implementations highly expected by top software houses in Pakistan.
Interview Questions
4 TotalWhat is the main difference between an Interface and an Abstract Class in PHP?
An interface can only contain method signatures (no implementation), and a class can implement multiple interfaces. An abstract class can have both signatures and implementations, but a class can only inherit from one abstract class.
What are Traits in PHP and how do they solve the multiple inheritance problem?
Traits are a mechanism for code reuse. A trait is similar to a class, but it is purely intended to group functionality in a fine-grained and consistent way. They allow developers to reuse sets of methods freely in several independent classes, overcoming single inheritance limitations in PHP.
Explain the concept of Late Static Binding in PHP.
Late static binding is used to reference the called class in a context of static inheritance using the `static::` keyword, rather than `self::` which refers to the class where the method is defined.
How would you prevent SQL Injection in vanilla PHP?
By using Prepared Statements (PDO or MySQLi), filtering inputs, and escaping outputs, rather than directly concatenating variables into SQL strings.