Top Answers to PHP Interview Questions

1. Compare PHP and Java.

Deployment areaServer-side scriptingGeneral-purpose programming
Language typeDynamically typedStatically typed
Providing a rich set of APIsNoYes

2. How can we encrypt a password using PHP?

The crypt () function is used to create one-way encryption. It takes one input string and one optional parameter. The function is defined as:

crypt (input_string, salt)

where input_string consists of the string that has to be encrypted and salt is an optional parameter. PHP uses DES for encryption. The format is as follows:

php code

3. Explain how to submit a form without a submit button.

A form can be posted or submitted without the button in the following ways:

  • On the OnClick event of a label in the form, a JavaScript function can be called to submit the form.
  • Using a Hyperlink: On clicking the link, a JavaScript function can be called.


Q5 php IQA code
  • A form can be submitted in the following ways as well without using the submit button:
    • Submitting a form by clicking a link
    • Submitting a form by selecting an option from the drop-down box with the invocation of an onChange event
    • Using JavaScript:
  • Using header(“location:page.php”);


4. How can we increase the execution time of a PHP script?

  • The default time allowed for a PHP script to execute is 30 seconds mentioned in the php.ini file. The function used is set_time_limit(int sec). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 seconds and 20 seconds is specified in set_time_limit(), the script will run for 45 seconds.
  • This time can be increased by modifying max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.
  • The script execution time can be increased by:
    • Using the sleep() function in the PHP script
    • Using the set_time_limit() function

The default limit is 30 seconds. The time limit can be set to zero to impose no time limit

To know more about PHP, enroll in our Online PHP Training Course now!

5. What is Zend Engine?

Zend Engine is used internally by PHP as a compiler and runtime engine. PHP Scripts are loaded into memory and compiled into Zend OPCodes.

These OPCodes are executed and the HTML generated is sent to the client.

The Zend Engine provides memory and resource management and other standard services for the PHP language. Its performance, reliability, and extensibility have played a significant role in PHP’s increasing popularity.

6. What library is used for PDF in PHP?

The PDF functions in PHP can create PDF files using PDFlib version 6. PDFlib offers an object-oriented API for PHP5 in addition to the function-oriented API for PHP4.
There is also the » Panda module.

FPDF is a PHP class, which allows generating PDF files with pure PHP (without using PDFlib). F from FPDF stands for Free: we may use it for any requirement and modify it to suit our needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.

7. What are the new features introduced in PHP7?

  • Zend Engine 3 performance improvements and 64-bit integer support on Windows
  • Uniform variable syntax
  • AST-based compilation process
  • Added Closure::call()
  • Bitwise shift consistency across platforms
  • (Null coalesce) operator
  • Unicode codepoint escape syntax
  • Return type declarations
  • Scalar type (integer, float, string, and Boolean) declarations

8. What is htaccess? Why do we use it and where?

The .htaccess files are configuration files of Apache Server that provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory; the directives apply to that directory and all subdirectories thereof.

These .htaccess files are used to change the functionality and features of the Apache web server.

For instance:

  • The .htaccess file is used for URL rewrite.
  • It is used to make the site password-protected.
  • It can restrict some IP addresses so that on these restricted IP addresses, the site will not open.

9. What are magic methods?

Magic methods are member functions that are available to all the instances of a class. Magic methods always start with ‘__’, for example, __construct(). All magic methods need to be declared as public.

To use a method, it should be defined within the class or the program scope. Various magic methods used in PHP5 are:

  • __construct()
  • __destruct()
  • __set()
  • __get()
  • __call()
  • __toString()
  • __sleep()
  • __wakeup()
  • __isset()
  • __unset()
  • __autoload()
  • __clone()

10. What is meant by PEAR in PHP?

PEAR is an acronym for PHP Extension and Application Repository. The purpose of PEAR is to provide:

  • A structured library of open-sourced code for PHP users
  • A system for code distribution and package maintenance
  • A standard style for writing code in PHP
  • PHP Foundation Classes (PFC)
  • PHP Extension Community Library (PECL)
  • A website, mailing lists, and download mirrors to support the PHP/PEAR community


11. Explain soundex() and metaphone().

The soundex() function calculates the soundex key of a string. A soundex key is a 4-character long alphanumeric string that represents the English pronunciation of a word. The soundex() function can be used for spelling applications.

$str= “hello”;
Echo soundex($str);

The metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if it is pronounced by an English (native) person. This function can also be used for spelling applications.

echo metaphone(“world”);

12. What is Smarty?

Smarty is a template engine written in PHP. Typically, these templates will include variables—like {$variable}—and a range of logical and loop operators to allow adaptability within the templates.

13. What is Memcache?

Memcache is a technology that caches objects in memory such that a web application can get to them really fast. It is used by sites, such as Digg, Facebook, and NowPublic, and is widely recognized as an essential ingredient in scaling any LAMP.

14. How can we execute a PHP script using a command line?

We just have to run the PHP CLI (Command-line Interface) program and provide the PHP script file name as the command-line argument, for example, php myScript.php, assuming php as the command to invoke the CLI program.

We have to keep in mind that if our PHP script is written for the Web CGI interface, it may not execute properly in the command-line environment.

10 thoughts on “Top PHP Interview Questions and Answers”

Leave a Reply

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

Solve : *
16 + 20 =

Interview Questions