Beginner to intermediate PHP questions on syntax, OOP, sessions, error handling and databases, for backend and full-stack roles.
Basics
What is PHP and what are its key features?
PHP is a server-side scripting language built for web development. It is open source, easy to pick up, works well with databases and supports object-oriented programming.
How do you define a variable in PHP?
Variables start with $ followed by the name and are dynamically typed. Constants are defined with define() or const.
What is the difference between echo and print?
Both output strings. echo can take several parameters and returns nothing; print takes one parameter and returns 1.
What is the difference between == and === in PHP?
== compares values after type juggling. === compares both value and type.
Object-oriented PHP
What is the difference between public, private and protected?
Public members can be accessed from anywhere. Private members only from within the class. Protected members from the class and its child classes.
Explain interfaces in PHP.
An interface declares method signatures without implementing them. A class can implement several interfaces, which makes them useful for contract-based design.
What are traits in PHP?
Traits are groups of methods you can include in classes. They allow code reuse in a single-inheritance language without duplicating code.
Sessions, databases and errors
How do you connect PHP to MySQL?
With mysqli_connect() or PDO. PDO is usually preferred because it supports prepared statements and works with other databases.
How does PHP handle error reporting?
Through error_reporting(), ini_set() and try-catch blocks for exceptions. You can log errors or display them depending on the environment.
Related: hire PHP developers and the PHP developer salary guide.
Keep reading
Same skill, other angles
- Hire Drupal developers who ship production-ready Drupal sitesHire developers
- Hire contract Magento and Adobe Commerce developersHire developers
- PHP developer salary in IndiaSalaries & rates
- Drupal 7 end of life: what to do now and who to hire for the migrationBlog
- Magento vs Adobe Commerce vs Shopify Plus: hiring e-commerce developers in IndiaBlog

