Home / Interview / PHP :: General Questions

Interview :: PHP

11) List some of the features of PHP7.
  • Scalar type declarations
  • Return type declarations
  • Null coalescing operator (??)
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Closure::call method
  • Group use declaration
  • Generator return expressions
  • Generator delegation
  • Space ship operator
12) 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.

Syntax:

13) What is "print" in PHP?

PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.

Syntax:

14) 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.

15) How a variable is declared in PHP?

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

Syntax:

16) What is the difference between $message and $$message?

$message stores variable data while $$message is used to store variable of variables.

$message stores fixed data whereas the data stored in $$message may be changed dynamically.

17) What are the ways to define a constant in PHP?

PHP constants are name or identifier that can't be changed during execution of the script. PHP constants are defined in two ways:

  • Using define() function
  • Using const() function
18) What are magic constants in PHP?

PHP magic constants are predefined constants, which change based on their use. They start with a double underscore (__) and end with a double underscore (__).

19) How many data types are there in PHP?

PHP data types are used to hold different types of data or values. There are 8 primitive data types which are further categorized in 3 types:

  • Scalar types
  • Compound types
  • Special types
20) How to do single and multi line comment in PHP?

PHP single line comment is made in two ways:

  • Using // (C++ style single line comment)
  • Using # (Unix Shell style single line comment)

PHP multi-line comment is made by enclosing all lines within.