Programming MCQs Feed

📊 PHP
Q. Which keyword refers to the current class?
  • (A) this
  • (B) self
  • (C) static
  • (D) parent
💬 Discuss
✅ Correct Answer: (B) self

Explanation: self refers to the current class.

📊 PHP
Q. Which PHP feature allows dependency injection?
  • (A) Traits
  • (B) Type hinting
  • (C) Namespaces
  • (D) Autoloading
💬 Discuss
✅ Correct Answer: (B) Type hinting

Explanation: Type hinting helps inject dependencies.

📊 PHP
Q. Which Composer file defines project dependencies?
  • (A) composer.lock
  • (B) composer.json
  • (C) package.json
  • (D) autoload.php
💬 Discuss
✅ Correct Answer: (B) composer.json

Explanation: composer.json defines dependencies.

📊 PHP
Q. Which PHP function converts an array or object into JSON?
  • (A) json_encode()
  • (B) json_decode()
  • (C) array_to_json()
  • (D) encode_json()
💬 Discuss
✅ Correct Answer: (A) json_encode()

Explanation: json_encode() converts PHP data to JSON.

📊 PHP
Q. Which PHP function converts JSON into an associative array?
  • (A) json_encode()
  • (B) json_decode($json, true)
  • (C) json_parse()
  • (D) decode_json()
💬 Discuss
✅ Correct Answer: (B) json_decode($json, true)

Explanation: Second parameter true returns an associative array.

📊 PHP
Q. Which HTTP status code represents successful resource creation?
  • (A) 200
  • (B) 201
  • (C) 204
  • (D) 202
💬 Discuss
✅ Correct Answer: (B) 201

Explanation: 201 Created indicates a new resource was created.

📊 PHP
Q. Which HTTP status code indicates a bad request?
  • (A) 400
  • (B) 401
  • (C) 403
  • (D) 404
💬 Discuss
✅ Correct Answer: (A) 400

Explanation: 400 means the request syntax or data is invalid.

📊 PHP
Q. Which HTTP status code indicates unauthorized access?
  • (A) 400
  • (B) 401
  • (C) 403
  • (D) 404
💬 Discuss
✅ Correct Answer: (B) 401

Explanation: 401 indicates authentication is required.

📊 PHP
Q. Which HTTP status code indicates forbidden access?
  • (A) 401
  • (B) 402
  • (C) 403
  • (D) 405
💬 Discuss
✅ Correct Answer: (C) 403

Explanation: 403 means access is forbidden.

📊 PHP
Q. Which HTTP method is used to update an entire resource?
  • (A) POST
  • (B) PUT
  • (C) PATCH
  • (D) GET
💬 Discuss
✅ Correct Answer: (B) PUT

Explanation: PUT replaces the entire resource.