PHP Interview Questions – Set 03

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 (__).

What does isset() function?

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

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:

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

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.

Differentiate between require and include?

Require and include both are used to include a file, but if data is not found include sends warning whereas require sends Fatal error.

Explain PHP parameterized functions.

PHP parameterized functions are functions with parameters. You can pass any number of parameters inside a function. These given parameters act as variables inside your function. They are specified inside the parentheses, after the function name. Output depends upon dynamic values passed as parameters into the function.

What is the method to register a variable into a session?

  1. <?php
  2. Session_register($ur_session_var);
  3. ?>

What is the difference between indexed and associative array?

The indexed array holds elements in an indexed form which is represented by number starting from 0 and incremented by 1. For example:

$season=array(“summer”,”winter”,”spring”,”autumn”);
The associative array holds elements with name. For example:

$salary=array(“Sonoo”=>”350000″,”John”=>”450000″,”Kartik”=>”200000”);

What are include() and require() functions?

The Include() function is used to put data of one PHP file into another PHP file. If errors occur, then the include() function produces a warning but does not stop the execution of the script, and it will continue to execute.

The Require() function is also used to put data of one PHP file to another PHP file. If there are any errors, then the require() function produces a warning and a fatal error and stops the script.

How to create connection in PHP?

The mysqli_connect() function is used to create a connection in PHP.

resource mysqli_connect (server, username, password)