PHP Interview Questions

Q10: What are the popular Content Management Systems (CMS) in PHP?


  • WordPress: WordPress is a PHP and MySQL-based free and open-source content management system (CMS). It has a plug-in architecture as well as a template system. It is mostly associated with blogging, although it also supports other types of web content, including more traditional mailing lists and forums, media displays, and online businesses.
  • Joomla: Open Source Matters, Inc. invented Joomla, a free and open-source content management system (CMS) for distributing web content. It is built on a model-view-controller web application framework that is independent of the CMS.
  • Magento: Magento is an open-source E-commerce programming developed by Varien Inc. that is useful for online businesses. It has a flexible measured design and is adaptable, with several control options that are beneficial to clients. Magento makes use of an e-commerce platform that provides organizations with advanced E-business solutions and a large support network.
  • Drupal: is a content management system (CMS) platform written in PHP and published under the GNU General Public License (General Public License).

Q11: What is $_SESSION in PHP?

Ans: A session generates a file in the server's temporary directory that stores registered session variables and their session id. During that visit, this information will be visible to all pages on the site. A setting in the php.ini file is called the session. Save path determines the location of the temporary record. When a session begins, the following events occur:

  • Ans initially creates two duplicates of a unique session id for that client's session, which is an arbitrary string of 32 hexadecimal digits, for example, 3c7foj34c3jjhkyepop2fc937e3443.
  • One copy of the unique session id is automatically transmitted to the user?s computer for future synchronization. One copy is kept on the server-side while the session is active.
  • Whenever you browse a page of a website or web app, the current user's session id is linked with the HTTP header, and this is compared to the session id stored on the server. You can browse the page of the website or web app after finishing the comparing procedure.
  • A session terminates when the user quits the browser or leaves the site; the server will terminate the session after a specified length of time, often 30 minutes.

Q12: How to terminate the execution of a script in PHP?

Ans: In PHP, the exit() method is used to end the script's execution. It is a built-in function that prints a message before terminating the current script. The message to be shown is provided to the exit() method as a parameter. This function will terminate the script after showing the message. It is an abbreviation for the function die(). It doesn't return anything.

Syntax: exit(message)

Where the message is a parameter to be passed as an argument. It defines a message or status.

Example: The code given below will print a message and exit the current script.

<?php $site = ""; fopen($site,"r") or exit("Unable to connect to $site"); ?>

Q13: How to connect to a URL in PHP?

Ans: By utilizing the cURL library, any URL may be linked to PHP. This is included as a default library with the basic PHP installation.

Client-side URL is abbreviated as cURL. cURL makes use of libcurl (client-side URL Transfer Library), which supports a variety of protocols such as FTP, FTPS, HTTP/1, HTTP POST, HTTP PUT, HTTP proxy, HTTPS, IMAP, Kerberos, and others. It enables you to connect to a URL and retrieve and display information from that page, such as HTML text, HTTP headers, related data, etc.

Q14: What is PDO in PHP?

Ans: PDO is an abbreviation for PHP Data Object. PDO is a collection of PHP extensions that include a basic PDO class as well as database-specific drivers. The PDO extension may connect to any database developed using the PDO driver. PDO drivers are available for FreeTDS, Microsoft SQL Server, IBM DB2, Sybase, Oracle Call Interface, Firebird/Interbase 6, and PostgreSQL databases.

It provides a data-access abstraction layer that is lightweight and vendor-neutral. As a result, regardless of whatever database we choose, the function for issuing queries and retrieving data will be the same. Furthermore, it focuses on data access abstraction rather than database abstraction.

Explain type hinting in PHP

Type hinting is used in PHP to define the anticipated data type (arrays, objects, interfaces, and so on) for an argument in a function declaration. PHP 5 was the first to include it. When the function is called, PHP checks to see if the parameters are of the user-preferred type. If the argument is not of the required type, the run time will display an error message, and the program will not run. It aids in better code structure and error message improvement.

Example usage:

//sendEmail() function argument $email is type hinted of Email Class. It means to call this function; you must pass an email object; otherwise, an error is generated.

<?PHP function sendEmail (Email $email) { $email->send(); } ?>