PHP Advanced Questions Interview Preparation

Level          Type


Advanced                    OOP, MySQL integration, validation, security, APIs, error handling


1. What is OOP in PHP?
➤ Object-Oriented Programming allows organizing code using classes and objects.

2. What are classes and objects?
➤ A class is a blueprint; objects are instances of a class.

3. What is inheritance in PHP?
➤ One class can inherit methods and properties from another class using extends

4. What is an interface in PHP?
➤ Defines methods a class must implement.

5. What are constructors and destructors?
__construct() runs when an object is created, __destruct() runs when it is destroyed.

6. What is abstraction?
➤ Hiding internal details and showing only the functionality.

7. What is encapsulation?
➤ Restricting access to class members using private/protected/public.

8. What is a trait in PHP?
➤ A trait is a reusable collection of methods for multiple classes.

9. How do you connect PHP to MySQL?
➤ Using mysqli_connect() or PDO.

10. Write a basic MySQL query in PHP.
$conn = mysqli_connect("localhost", "root", "", "db");
$result = mysqli_query($conn, "SELECT * FROM users");

11. How to prevent SQL injection?
➤ Use prepared statements or mysqli_real_escape_string().

12. What is XSS and how to prevent it?
➤ Cross-Site Scripting; use htmlspecialchars() to sanitize input.

13. What are APIs in PHP?
➤ PHP can consume or create REST APIs using curl or built-in functions.

14. What is curl in PHP?
➤ It allows making HTTP requests from a PHP script.

15 .What are namespaces in PHP?
➤ They help avoid name conflicts in large applications.

16.  What is autoloading?
➤ Automatically loads classes using spl_autoload_register().

17 .How to handle errors in PHP?
➤ Using try, catch, and throw.

18 . What is a static method? 
➤ A method that can be called without creating an object.

19 . What is the difference between abstract class and interface?
➤ Abstract class can have method body, interface can’t.

20. What is MVC in PHP?
➤ Model-View-Controller architecture for structured application development.














































Comments

Popular posts from this blog

PHP INTERVIEW QUESTIONS

PHP Intermediate Questions Interview Preparation

PHP Interview Questions (Beginner Level) – Short Answers