PHP Interview Questions and Answers
This article presents a collection of PHP interview questions covering function existence, language constructs, array handling, error types, and code snippets, each accompanied by explanations of the correct answers and underlying PHP behavior.
1. What is the output of the following code?
A. Empty B. true C. false D. FALSE
<code>echo function_exists('print');</code>Explanation: print is a language construct, so function_exists() returns false; echoing false produces no output.
2. Which of the following is a function?
A. array B. eval C. each D. list
Explanation: array , eval , and list are language constructs, while each is a function.
3. Which function will return TRUE when added?
A. ord(65) B. chr(65) C. 65+'' D. ''+65
<code>return ? == 'A';</code>Explanation: ord('A') converts the character to its ASCII number, whereas chr(65) converts the number back to a character.
4. What is the output of the following code?
A. hello B. empty C. error D. hellohello
<code>$a[bar] = 'hello';</code><code>echo $a[bar];</code><code>echo $a['bar'];</code>Explanation: The index bar can be used without quotes, but quoting it is recommended.
5. Which code will output "banana"?
<code>$arr = ['name'=>'banana'];</code>Options:
A. echo "{$res['name']}";
B. echo "$res['name']";
C. echo "{$res[name]}";
D. echo "$res[name]";
Explanation: Within double quotes, array keys that are strings must not be quoted unless wrapped in braces.
6. Which error type cannot be captured by the standard error handler?
A. E_WARNING
B. E_USER_ERROR
C. E_PARSE
D. E_NOTICE
Explanation: (see table below)
Error Type
Description
E_ERROR
Fatal runtime error; script terminates.
E_WARNING
Runtime warning; script continues.
E_PARSE
Compile-time syntax error.
E_NOTICE
Runtime notice; non-fatal.
E_USER_ERROR
User-generated error via
trigger_error().
7. Which error type cannot be caught by a custom error handler?
A. E_WARNING
B. E_USER_ERROR
C. E_PARSE
D. E_NOTICE
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.