Top Interview PHP Questions For Capgemini
Top Basic PHP Interview Questions and Answers for Capgemini
Β
Introduction
Preparing for a PHP interview at Capgemini? PHP (Hypertext Preprocessor) is one of the most popular server-side scripting languages used for web development. Capgemini, being a global IT company, evaluates candidates on core PHP concepts, object-oriented programming (OOP), database handling, error management, and security best practices.
This blog provides a comprehensive list of frequently asked PHP interview questions at Capgemini, suitable for both freshers and experienced professionals.
β Covers fundamental to advanced PHP topics
β Includes practical coding examples
β Useful for technical interviews at Capgemini
π Bookmark this page to revise the most important PHP interview questions before your Capgemini interview! π
Top Basic PHP Interview Questions and Answers
1. What is PHP?
Answer: PHP (Hypertext Preprocessor) is an open-source, server-side scripting language designed for web development. It is widely used for creating dynamic and interactive web pages.
2. What are the key features of PHP?
Answer:
- Open-source β Free to use and widely supported
- Server-side scripting β Executes on the server before sending output to the client
- Cross-platform compatibility β Runs on Windows, Linux, and macOS
- Database support β Works with MySQL, PostgreSQL, SQLite, etc.
- Integration with HTML and JavaScript β Can be embedded within HTML
3. What is the difference between PHP and JavaScript?
Answer:
Feature | PHP | JavaScript |
---|---|---|
Execution | Server-side | Client-side |
Usage | Backend development | Frontend scripting |
Database Support | Yes | No (requires Node.js) |
4. How do you declare a variable in PHP?
Answer: In PHP, variables start with the $
symbol.
Example:
$company = "Capgemini";
echo $company;
5. What are the different data types in PHP?
Answer:
- String (
$name = "Capgemini";
) - Integer (
$age = 30;
) - Float (
$price = 99.99;
) - Boolean (
$isAvailable = true;
) - Array (
$colors = ["Red", "Blue", "Green"];
) - Object (Created using classes)
- NULL (
$value = NULL;
)
6. What are the different types of errors in PHP?
Answer:
- Notice Errors β Minor errors that donβt stop script execution
- Warning Errors β More serious, but script continues running
- Fatal Errors β Causes script to stop execution
- Parse Errors β Syntax errors in PHP code
Example:
echo $undefinedVariable; // Notice Error
7. What is the difference between echo
and print
in PHP?
Answer:
Feature | echo | |
---|---|---|
Syntax | echo "Hello"; | print "Hello"; |
Return Value | No return value | Returns 1 |
Performance | Faster | Slower |
8. What are PHP superglobals?
Answer:
$_GET
β Collects form data sent via URL$_POST
β Collects form data sent via HTTP POST$_SESSION
β Stores session variables$_COOKIE
β Stores cookies$_FILES
β Handles file uploads$_SERVER
β Contains server and request details
Example:
echo $_SERVER['SERVER_NAME'];
9. How do you connect PHP to a MySQL database?
Answer:
$connection = mysqli_connect("localhost", "root", "password", "database");
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully!";
10. What is the difference between include
and require
in PHP?
Answer:
Function | include | require |
---|---|---|
Execution | Continues if file is missing | Stops execution if file is missing |
Use case | Optional file | Mandatory file |
Example:
include 'header.php';
require 'config.php';
11. What are PHP sessions?
Answer: Sessions store user data across multiple pages.
Example:
session_start();
$_SESSION["username"] = "CapgeminiUser";
echo $_SESSION["username"];
12. What is the difference between isset()
and empty()
in PHP?
Answer:
Function | isset() | empty() |
---|---|---|
Checks | If variable is set | If variable is empty |
Example | isset($x) | empty($x) |
13. How do you handle errors in PHP?
Answer:
try {
throw new Exception("An error occurred");
} catch (Exception $e) {
echo $e->getMessage();
}
14. What is the purpose of the $_FILES
array in PHP?
Answer: It handles file uploads.
Example:
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
15. What are cookies in PHP?
Answer: Cookies store small amounts of data in the user’s browser.
Example:
setcookie("username", "CapgeminiUser", time() + 3600, "/");
echo $_COOKIE["username"];
16. What is the difference between GET and POST methods in PHP?
Answer:
Method | GET | POST |
---|---|---|
Data Sent | URL Parameters | HTTP Body |
Security | Less secure | More secure |
Example | $_GET['name'] | $_POST['name'] |
17. How do you create an associative array in PHP?
Answer:
$employee = ["name" => "John", "age" => 30];
echo $employee["name"];
18. What is object-oriented programming (OOP) in PHP?
Answer: OOP allows using classes and objects.
Example:
class Car {
public $brand;
function setBrand($name) {
$this->brand = $name;
}
}
$myCar = new Car();
$myCar->setBrand("Toyota");
echo $myCar->brand;
19. What is the difference between abstract classes and interfaces in PHP?
Answer:
Feature | Abstract Class | Interface |
---|---|---|
Methods | Can have concrete methods | All methods are abstract |
Properties | Can have properties | Cannot have properties |
Use | Extend with extends | Implement with implements |
20. How do you prevent SQL injection in PHP?
Answer: Using prepared statements.
Example:
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
This list of PHP interview questions for Capgemini covers the fundamentals and advanced topics that will help you excel in your interview. π