Call us: +91-9962812914  |  +91-9962812876 |

Top 20 PHP Interview Questions and Answers

What exactly does PHP do?

It can create custom content based on different variables

It is excellent at tracking user information

It can write or read information to databases, if partnered with a database language

It can run on any type of platform and servers

It can do anything a standard HTML file

1) Is multiple inheritance supported in PHP?

PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ‘extended’.

2) What is the meaning of a final class and a final method?

‘final’ is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overrided.

3) How comparison of objects is done in PHP5?

We use the operator ‘==’ to test is two object are instanced from the same class and have same attributes and equal values. We can test if two object are refering to the same instance of the same class by the use of the identity operator ‘===’.

4) How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass informations from HTML to PHP.

5) What type of operation is needed when passing values through a form or an URL?

If we would like to pass values througn a form or an URL then we need to encode and to decode them using htmlspecialchars() and urlencode().

6) How can PHP and Javascript interact?

PHP and Javascript cannot directly interacts since PHP is a server side language and Javascript is a client side language. However we can exchange variables since PHP is able to generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.

7) What is needed to be able to use image function?

GD library is needed to be able execute image functions.

8) What is the use of the function ‘imagetypes()’?

imagetypes() gives the image format and types supported by the current version of GD-PHP.

9) What are the functions to be used to get the image’s properties (size, width and height)?

The functions are getimagesize() for size, imagesx() for width and imagesy() for height.

10) How failures in execution are handled with include() and require() functions?

If the function require() cannot access to the file then it ends with a fatal error. However, the include() function gives a warning and the PHP script continues to execute.

11) What library is used for pdf in PHP?

The PDF functions in PHP can create PDF files using the PDFlib library Version 6. PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4.
There is also the » Panda module. FPDF is a PHP class, which allows generating PDF files with pure PHP (without using the PDFlib library.)
F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.

12)  How can we execute a PHP script using command line?

  • Just 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” is the command to invoke the CLI program.
  • Remember that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

13) Which PHP Extension help to debug the code?

Xdebug: – It uses the DBGp debugging protocol for debugging.
The debug information that Xdebug can provide includes the following:

  • stack and function traces in error messages with:
  • full parameter display for user defined functions
  • function name, file name and line indications
  • support for member functions
  • memory allocation
  • protection for infinite recursions

14) Explain how to send large amounts of emails using PHP.

There are different methods through which we can send mails in PHP. They are as follows:

15) PHP mail() function
It implicitly sends a message to SMTP server, which is configured in the php.ini file. This function is used by the base class of MIME message composing and sending package.

16)SMTP server relay
They are used to relay the messages to an intermediate SMTP server. This server stores the     messages temporarily and will try to deliver them in the destination SMTP server.

17) Sending urgent messages by doing direct delivery to the destination SMTP server
A variable named direct_delivery is provided by the smtp_message_class sub-class, which connects to the destination SMTP server and sends the message directly.

18) Write down the code for save an uploaded file in php.

if ($_FILES[“file”][“error”] == 0)
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];

19) How to create a text file in php?

  1. $filename = “/home/user/guest/newfile.txt”;
    $file = fopen( $filename, “w” );
    if( $file == false )
    echo ( “Error in opening new file” ); exit();
    fwrite( $file, “This is a simple test\n” );
    fclose( $file );

20) How to strip whitespace (or other characters) from the beginning and end of a string ?

The trim() function removes whitespaces or other predefined characters from both sides of a string.


Leave a comment

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