PHP Interview Questions – Part 2

1. What is use of header() function in php ?

Answer :- The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.

2. List out the predefined classes in PHP?
Answer :-

3. What type of inheritance that PHP supports?

Answer :- In PHP an extended class is always dependent on a single base class,that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’.

4. How do you define a constant?
Answer :-
Constants in PHP are defined using define() directive, like define(“MYCONSTANT”, 100);

5. How do you pass a variable by value in PHP?
Answer :-
Just like in C++, put an ampersand in front of it, like $a = &$b;

6. What does a special set of tags do in PHP?

Answer :- The output is displayed directly to the browser.

7. How do you call a constructor for a parent class?

Answer :- parent::constructor($value)

8. What’s the special meaning of __sleep and __wakeup?

Answer :- __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

9. What is the difference between the functions unlink and unset?
Answer :-
unlink() deletes the given file from the file system.
unset() makes a variable undefined.

10. How many ways can we get the value of current session id?
Answer :-
session_id() returns the session id for the current session.

11. What are default session time and path?
Answer :-
default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp

12. for image work which library?
Answer :-
we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

13. How can we get second of the current time using date function?
Answer :-

14. What are the Formatting and Printing Strings available in PHP?
Answer :-
printf()- Displays a formatted string
sprintf()-Saves a formatted string in a variable
fprintf() -Prints a formatted string to a file
number_format()-Formats numbers as strings

15. How can we find the number of rows in a result set using PHP?
Answer :-
$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;

WordPress spam blocked by CleanTalk.
Skip to toolbar