PHP Interview Questions

Q1: What is a session in PHP?

Ans: A PHP session is a technique to store data utilized throughout several pages of a whole website. In contrast to cookies, the information is not saved on the user's computer. A session in which the registered session variables and values are saved will generate a file in a temporary server directory. All pages on the site during this visit will receive this information.

You launch the program, make some changes and then dismiss it while you work with the application. It's quite similar to a session. You know who you are, the computer. It recognizes when you start and finish your application.

But online, because the HTTP address doesn't keep a State, the webserver doesn't know who you are or how you do. This problem is resolved by saving user information across several pages with session variables (e.g., username, favorite color, etc.). Session variables are used by default until the user exits the browser. Session variables, therefore, include user information, and all pages in one application are visible.

Q2: How can we increase the execution time of a PHP script?

Ans: By default, PHP programs have a maximum runtime of 30 seconds. PHP pauses the script and returns a bug if it takes longer than 30 seconds. The max_execution_time directive in the file php.ini allows you to modify the time of script running.

The function set_time_limit resets the timeout from zero when the script is invoked. This implies that if the default timer is set to 30 sec and 20 sec in set_time_limit(), the script is set to 45 seconds. The script takes an infinite duration when 0sec is given.

Q3: Explain the main types of errors.

Ans: In PHP, the three most common forms of errors are:

  • Notices: Notices are non-critical mistakes that might occur during script execution. Users will not be able to see these. Accessing an undefined variable is an example.
  • Warnings are more serious than notices. Warnings do not cause the script to stop running. These are visible to the user by default. Include() a file that does not exist, for example.
  • Fatal: This is the most serious error category, and it instantly stops the script's execution. For example, attempting to access a property of a non-existent object or attempting to need() a non-existent file.

Q4: Is PHP a case-sensitive language?

Ans: PHP is a somewhat case-sensitive programming language. Variable names are case-sensitive, while function names are not. Furthermore, user-defined functions are not case-sensitive, although the rest of the language is. User-made functions in PHP, for example, can be declared in lowercase but afterward referred to in uppercase and still operate correctly.