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:

FeaturePHPJavaScript
ExecutionServer-sideClient-side
UsageBackend developmentFrontend scripting
Database SupportYesNo (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:

Featureechoprint
Syntaxecho "Hello";print "Hello";
Return ValueNo return valueReturns 1
PerformanceFasterSlower

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:

Functionincluderequire
ExecutionContinues if file is missingStops execution if file is missing
Use caseOptional fileMandatory 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:

Functionisset()empty()
ChecksIf variable is setIf variable is empty
Exampleisset($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:

MethodGETPOST
Data SentURL ParametersHTTP Body
SecurityLess secureMore 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:

FeatureAbstract ClassInterface
MethodsCan have concrete methodsAll methods are abstract
PropertiesCan have propertiesCannot have properties
UseExtend with extendsImplement 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. πŸš€

Leave a Reply

Your email address will not be published. Required fields are marked *