PHP 7 interview questions

PHP 7 interview questions | Freshers & Experienced

  • Arushi
  • 20th Jul, 2019
  • 600 Followers

PHP 7 interview questions

Q1. What's new in PHP7?

New features of PHP 7 are  - 

  1. Scalar type declaration
  2. Return type declarations
  3. Null coalescing operator
  4. Spaceship operator
  5. Constant arrays using define
  6. Anonymous classes
  7. Unicode codepoint escape syntax
  8. Closure::call
  9. Filtered unserialize
  10. IntlChar
  11. Expectations
  12. Group use declarations
  13. Generator Return Expressions
  14. Generator delegation
  15. Integer division with intdiv
  16. Session options
  17. preg_replace_callback_array
  18. CSPRNG Functions

Q2. How to upgrade the version of PHP 5 to PHP 7?

Q3. What is Null Coalesce Operator?

Null Coalesce Operator (??) is introduced in PHP 7. This operator is used as a replacement of isset() along with the ternary operator (?:). The Null Coalesce operator (??) returns the result of its first operand if it exists and is not NULL, or else it will return its second operand.

Q4. Explain Scalar type declarations in PHP7.

Scalar type declarations is a new feature of PHP that is introduced in PHP 7. There are two options of Scalar type declaration are available.

  • Strict
  • Coercive

Q5. What are anonymous classes in PHP7.

Anonymous Class in PHP is new way of creating object without the need to name them. Anonymous classes are created and initiated at same time.

Example of an Anonymous Class in PHP

$object =new class('argument'){

public $property;

public function __construct($argument){

	$this->property=$argument;

}

}

Q6. What is Coercive mode in PHP?

Coercive mode in PHP is the default mode of Scalar type declarations (Feature introduced in PHP 7).

Q7. What is Strict mode in PHP?

Strict mode is new feature in PHP in which variable declaration is required before using it.

Q8. What are Array constants?

In PHP 5.6 or we can define constants as a scalar expression. We can define an array constant using the define keyword.

Array Constant Example in PHP

 define('fruits', [
      'apple',
      'mango',
      'banana'
   ]);
 print(fruits[2]); // outputs banana

Q9. Explain Spaceship Operator?

Spaceship operator also is known as (combined comparison operator) is a new operator introduced in PHP 7. This operator is denoted by "<=>". This single operator can perform greater than, less than, and equal comparison between two operands. Its behavior is similar like strcmp() or version_compare() functions and can be used with integers, floats, strings, arrays, objects, etc.

Q10. What is use of random_bytes() in PHP?

random_bytes() function in PHP is used to generate cryptographically secure pseudo-random bytes.

Syntax:

String random_bytes ( int $length )

Usage

$length = random_bytes('4'); 
  
//Print the reult and convert by binaryhexa 
var_dump(bin2hex($length)); 

Q11. List some features of PHP that are deprecated in PHP 7?

PHP Features that are deprecated in PHP 7 are.

  • PHP 4 style constructors
  • Static calls to non-static methods
  • password_hash() salt option
  • capture_session_meta SSL context option

Q12. What is use of set_exception_handler() in PHP?

set_exception_handler() is a library function in PHP. It is used to set the default exception handler if an exception is not caught within a try/catch block in PHP.exception_handler stop the execution of script.

Q13. List some extensions have been removed from PHP 7?

Following extensions are removed from PHP and are no longer in use

  • ereg
  • mssql
  • mysql
  • sybase_ct

Read More from https://www.php.net

About Author :

  • Author of PHP 7 interview questions

    Arushi Pandey

    Arushi Pandey is senior PHP developer and have hand on experience on PHP Frameworks and tools.He loves to share and write programming content on internet.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.