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.

php Courses
php Courses
php Courses
PHP Interview Questions and Answers

1. What is the output of the following code?

A. Empty  B. true  C. false  D. FALSE echo function_exists('print'); 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 return ? == 'A'; 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

$a[bar] = 'hello';</code><code>echo $a[bar];</code><code>echo $a['bar'];

Explanation: The index bar can be used without quotes, but quoting it is recommended.

5. Which code will output "banana"? $arr = ['name'=>'banana']; 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

programminginterviewQuiz
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.