Sei sulla pagina 1di 3

PHP Interview questions

1. What is the difference between language construct and function? say some examples in
php?

Ans:

# Language constructs is faster than function.


Because language constructs are highly optimized in the interpreter.

# No need to call any external library to execute the language constructs.

# Function get more resource compare to Language constructs.

# In type casting int is faster than intval() function

Example language constructs

1. echo()
2. empty()
3. isset()
4. unset()
5. eval()
6. exit()
7. die()
8. include()
9. include_once()
10. require()
11. require_once()
12. return

2. What is different between exit and die?

Answer

Exit and die both are language constructs.


Exit is after php 3 only will be implemented in php.

3. How can set the cookie in javascript?

Answer
var cookiename = 'testcookie';

var value = 'costrategix';

var expiredays = 30;

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

document.cookie=cookiename+ "=" +escape(value)+


((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

4. What about the session Id? Can we assign the value to session id?

Answer

When we open the site using http protocol, that time the server will
generate one unique alpha numeric id.
That id will store in tmp folder in server and the same id will stored cookie
path in client side.
That Id is called session id. We can assign the value in php.

Example
session_id($value);

When the request url will be changed that time the new session id will
be generated. The server will be watched which id is in idle that id
goes to the garbage collection folder in server.

5. Which one is speed from this echo and print? why?


Answer

* echo and print both are language constructs in php.

* echo will not return anything.

* print will return boolean type data(true/false).

* echo is faster than print


* echo will support mulitple parameter without brackets.

* print will not support mulitple parameter.

* echo will not support between the expression.

* Ex: ($a>$b)? echo $a:echo $b; // will through error

* print will support

* Ex: ($a>$b)? print $a:print $b; // will work perfect

6. What is the default port for apache?

Answer

Port : 80

7. If we set error off in php.ini file? What happen? Any error through browse or error will
store? If its store where it will store?

Answer

display_errors = off

In Browser, errors will not be display. But all errors will be stored log
file in server.

Potrebbero piacerti anche