PHP Interview Questions

There is given PHP interview questions and answers that have been asked in many companies. Let's see the list of top PHP interview questions.

Explain isset() function?

The isset() function checks if the particular variable is set and has a value other than NULL. The function returns Boolean – false if the variable is not set or true if the variable is set. The function can check multiple values: isset(var1, var2, var3…).

What is “echo” in PHP?

PHP echo output one or more string. It is a language construct not a function. So the use of parentheses is not required. But if you want to pass more than one parameter to echo, the use of parentheses is required.

void echo ( string $arg1 [, string $… ] )
.

What is the difference between static and dynamic websites?

Static Websites Dynamic Websites
In static websites, content can’t be changed after running the script. You cannot change anything in the site as it is predefined. In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visits or reloads.
.

Explain magic constants in PHP?

Magic constants start and end with double underscores and are predefined constants that change their value based on context and usage. There are 9 magic constants in PHP:

__LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __TRAIT__, __METHOD__, __NAMESPACE__, ClassName::class
.

How to run the interactive PHP shell from the command line interface?

Just use the PHP CLI program with the option -a as follows:

php -a
.

Explain various data types of PHP?

There are different data types in PHP:

  • String: a sequence of characters, e.g.,” Blog.io.”
  • Float: a floating-point (decimal) number, e.g., 23.456
  • Integer: an integer, e.g. 12
  • Boolean: represents two states – true, false.
  • Object: stores values of different data types into single entity, eg. apple = new Fruit();
  • Array: stores multiple values of same type, eg. array(“red”, “yellow”, “blue”)
  • NULL: when no value is assigned to a variable, it can be assigned NULL. For example, $msg = NULL;
.

What are the common usage of PHP?

Common uses of PHP −

  • PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.
  • You add, delete, modify elements within your database thru PHP.
  • Access cookies variables and set cookies.
  • Using PHP, you can restrict users to access some pages of your website.
  • It can encrypt data
.

Which programming language does PHP resemble?

PHP syntax resembles Perl and C.

How to execute a PHP script from the command line?

To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way:

php script.php
.

What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages” automatically..