PHP Interview Questions and Answers Set – 5

In this tutorial we are providing some set of frequently asked PHP Interview Questions for experienced candidates which will help them to get success in interview. Read PHP Interview Questions and Answers Set – 4.

  1. What is the difference between ereg_replace() and eregi_replace()?

    The function eregi_replace() is identical to the function ereg_replace() except that it ignores case distinction when matching alphabetic characters.

  2. Is it possible to protect special characters in a query string?

    Yes, we use the urlencode() function to be able to protect special characters.

  3. What are the three classes of errors that can occur in PHP?

    The three basic classes of errors are notices (non-critical), warnings (serious errors) and fatal errors (critical errors).

  4. What is the difference between characters \034 and \x34?

    \034 is octal 34 and \x34 is hex 34.

  5. How can we pass the variable through the navigation between the pages?

    It is possible to pass the variables between the PHP pages using sessions, cookies or hidden form fields.

  6. Is it possible to extend the execution time of a php script?

    The use of the set_time_limit(int seconds) enables us to extend the execution time of a php script. The default limit is 30 seconds.

  7. Is it possible to destroy a cookie?

    Yes, it is possible by setting the cookie with a past expiration time.

  8. What is the default session time in php?

    The default session time in php is until closing of browser

  9. Define Object-Oriented Methodology

    Object orientation is a software programming methodology that is based on the modeling a real world system.An object is the core concept involved in the object orientation. An object is the copy of the real world entity.An object oriented model is a collection of objects and its inter-relationships.

  10. How do you define a constant?

    Using define() directive, like define (“CONSTANT”, 150)

  11. What does $_FILES means?

    $_FILES is an associative array composed of items sent to the current script via the HTTP POST method.

  12. What is the difference between $_FILES[‘pic’][‘name’] and $_FILES[‘pic’][‘tmp_name’]?

    $_FILES[‘pic’][‘name’] represents the original name of the file on the client machine,
    $_FILES[‘pic’][‘tmp_name’] represents the temporary filename of the file stored on the server.

    How can we get the error when there is a problem to upload a file?

    $_FILES[‘pic’][‘error’] contains the error code associated with the uploaded file.

  13. How can we change the maximum size of the files to be uploaded?

    We can change the maximum size of files to be uploaded by changing upload_max_filesize in php.ini.

  14. How send email using php?

    To send email using PHP, you use the mail() function.This mail() function accepts 5 parameters as follows (the last 2 are optional). You need webserver, you can’t send email from localhost. eg :

    mail($to, $subject, $message, $headers);
  15. What is the use of “ksort” in php?

    It is used for sort an array by key in reverse order.

  16. What does the scope of variables means?

    The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well.

  17. what the difference between the “BITWISE AND” operator and the “LOGICAL AND” operator?

    $a and $b: TRUE if both $a and $b are TRUE.

    $a & $b: Bits that are set in both $a and $b are set.

  18. What are the two main string operators?

    The first is the concatenation operator (‘.’), which returns the concatenation of its right and left arguments. The second is (‘.=’), which appends the argument on the right to the argument on the left.

  19. What does the array operator ‘===’ means?

    $a === $b TRUE if $a and $b have the same key/value pairs in the same order and of the same types.

  20. What is the differences between $a != $b and $a !== $b?

    != means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b).

  21. What does $_ENV means?

    $_ENV is an associative array of variables sent to the current PHP script via the environment method.

  22. How can we determine whether a variable is set?

    The boolean function isset determines if a variable is set and is not NULL.

  23. What is the difference between the functions strstr() and stristr()?

    The string function strstr(string allString, string occ) returns part of allString from the first occurrence of occ to the end of allString. This function is case-sensitive. stristr() is identical to strstr() except that it is case insensitive.

  24. What is the difference between for and foreach?

    for is expressed as follows:

    for (expr1; expr2; expr3)


    The first expression is executed once at the beginning. In each iteration, expr2 is evaluated. If it is TRUE, the loop continues and the statements inside for are executed. If it evaluates to FALSE, the execution of the loop ends. expr3 is tested at the end of each iteration.

    However, foreach provides an easy way to iterate over arrays and it is only used with arrays and objects.

  25. Is it possible to submit a form with a dedicated button?

    It is possible to use the document.form.submit() function to submit the form.
    For example:

    <input type="button" value="SUBMIT" />
  26. What is PEAR?

    PEAR is a framework and distribution system for reusable PHP components.The project seeks to provide a structured library of code, maintain a system for distributing code and for managing code packages, and promote a standard coding style.PEAR is broken into three classes: PEAR Core Components, PEAR Packages, and PECL Packages. The Core Components include the base classes of PEAR and PEAR_Error, along with database, HTTP, logging, and e-mailing functions. The PEAR Packages include functionality providing for authentication, networking, and file system features, as well as tools for working with XML and HTML templates.

  27. Distinguish between urlencode and urldecode?

    This method is best when encode a string to used in a query part of a URL. it returns a string in which all non-alphanumeric characters except -_. have replace with a percentage(%) sign . the urldecode->Decodes url to encode string as any %and other symbol are decode by the use of the urldecode() function.