skip to Main Content
For IT Training & Placement Call Us: 9350364233, 9813885367, 9813885348 or mail us on: admin@mctalenthunt.com
30 PHP Interview Questions With Answers

30 PHP Interview Questions with Answers

Share across

1) What is PHP?

PHP is a web language based on scripts that allow developers to dynamically create generated web pages.

2) Which programming language does PHP resemble?

PHP syntax resembles Perl and C

3) What does PEAR stand for?

PEAR means “PHP Extension and Application Repository”. It extends PHP and provides a higher level of programming for web developers.

4) What is the actually used PHP version?

Version 7.1 or 7.2 is the recommended version of PHP.

5) Explain the difference b/w static and dynamic websites?

In static websites, content can’t be changed after running the script. You can’t change anything on the site. It is predefined.

In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.

6) What is the name of scripting engine in PHP?

The scripting engine that powers PHP is called Zend Engine 2.

7) Explain the difference between PHP4 and PHP5.

PHP4 doesn’t support oops concept and uses Zend Engine 1.

PHP5 supports oops concept and uses Zend Engine 2.

8) What is the difference between “echo” and “print” in PHP?

Echo can output one or more string but print can only output one string and always returns 1.

Echo is faster than print because it does not return any value.

9) How a variable is declared in PHP?

A PHP variable is the name of the memory location that holds data. It is temporary storage.

10) What is the use of count() function in PHP?

The PHP count() function is used to count total elements in the array, or something an object.

11) What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this function.

12) What does isset() function?

The isset() function checks if the variable is defined and not null.

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

The final keyword in a method declaration indicates that the method cannot be overridden by subclasses. A class that is declared final cannot be subclassed. This is particularly useful when we are creating an immutable class like the String class. Properties cannot be declared final, only classes and methods may be declared as final.

14)  How can you compare objects in PHP?

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

15) How can PHP and Javascript interact?

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

16) What is overloading and overriding in PHP?

Overloading is defining functions that have similar signatures, yet have different parameters. Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that method. In PHP, you can only overload methods using the magic method __call.

17) What is the difference between $message and $$message in PHP?

They are both variables. But $message is a variable with a fixed name. $$message is a variable whose name is stored in $message. For example, if $message contains “var”, $$message is the same as $var.

18) How can we create a database using PHP and MySQL?

 The basic steps to create MySQL database using PHP are:

Establish a connection to MySQL server from your PHP script.

If the connection is successful, write a SQL query to create a database and store it in a string variable.

Execute the query.

19) How can we check the value of a given variable is alphanumeric?

It is possible to use the dedicated function, ctype_alnum to check whether it is an alphanumeric value or not.

20) How do I check if a given variable is empty?

If we want to check whether a variable has a value or not, it is possible to use the empty() function.

21) What does the unlink() function mean?

The unlink() function is dedicated for file system handling. It simply deletes the file given as entry.

22) What does the unset() function mean?

The unset() function is dedicated for variable management. It will make a variable undefined.

23) How can we define a variable accessible in functions of a PHP script?

This feature is possible using the global keyword.

24) How is it possible to return a value from a function?

A function returns a value using the instruction ‘return $value;’

25) What is the most convenient hashing method to be used to hash passwords?

It is preferable to use crypt() which natively supports several hashing algorithms or the function hash() which supports more variants than crypt() rather than using the common hashing algorithms such as md5, sha1 or sha256 because they are conceived to be fast. Hence, hashing passwords with these algorithms can create vulnerability.

26) Which cryptographic extension provide generation and verification of digital signatures?

The PHP-OpenSSL extension provides several cryptographic operations including generation and verification of digital signatures.

27) How do we use PHP to display information of a variable that’s readable by a human?

To achieve this result, we need to use print_r().

28) How do we set an infinite execution time for PHP script?

We add a set_time_limit(0) at the start of a script to make the time of execution infinite. This helps to prevent the PHP error of ‘maximum execution time exceeded.’ We can also specify this in the php.ini file.

29) Explain the PHP error ‘Parse error in PHP – unexpected T_variable at line x’.

This is a syntax error in PHP which tells us that a mistake at the line x stops parsing and executing the program.

30) How to export data into an Excel file?

Commonly, the data is obtained in a format supported by Excel. For instance, we can write a .csv file, select a separator between fields (a comma for example), and then proceed to open the file with Excel.

Back To Top

Thank You For Your Interest!

This demo session is free to attend, so fill out the form below to reserve your seat.