Ace Your Next Interview: Challenging PHP Concepts Quiz Quiz

  1. Question 1

    In PHP, which magic constant would dynamically contain the full path and filename of the file where it is used, even if that file is included from another script?

    1. __FILE__
    2. __DIR__
    3. __PATH__
    4. _FILENAME_
    5. __LINE__
  2. Question 2

    Suppose you have an undefined variable $foo; which PHP error type will be triggered when you try to echo $foo, and what is its impact on script execution?

    1. Notice; script continues to run
    2. Fatal Error; script execution stops
    3. Warning; script continues to run
    4. Parse Error; script execution stops before running
    5. Strict Error; script ignores the error
  3. Question 3

    Consider the two PHP comparison operations: (1) 0 == '0' and (2) 0 === '0'. What will be the respective results of these evaluations and why?

    1. (1) true, (2) false; == checks value, === checks type and value
    2. (1) false, (2) true; == checks type and value, === checks value only
    3. (1) false, (2) false; PHP does not allow such comparisons
    4. (1) true, (2) true; both operators check only value
    5. (1) error, (2) false; == throws a warning
  4. Question 4

    If you use the require() statement to include a missing PHP file, what will happen to script execution, and how does this differ from include()?

    1. A fatal error occurs and execution stops; include() only generates a warning
    2. The script continues as normal in both cases
    3. A notice is triggered and execution continues
    4. Nothing happens, both silently ignore the error
    5. Both result in fatal errors
  5. Question 5

    Given a scenario where you need to safely insert user data into a SQL table, which PDO technique best prevents SQL injection and why?

    1. Using prepared statements with bound parameters to separate query and data
    2. Interpolating user data directly into SQL strings
    3. Filtering input with htmlentities() before queries
    4. Escaping quotes manually using addshlashes()
    5. Switching database engines frequently