Programming MCQs Feed

📊 Trishul API
Q. What does get_status_code() return?
  • (A) String
  • (B) Boolean
  • (C) HTTP status code
  • (D) Response object
💬 Discuss
✅ Correct Answer: (C) HTTP status code

Explanation: Returns status code like 200, 404.

📊 Trishul API
Q. Which header is automatically set by json()?
  • (A) Content-Length
  • (B) Content-Type: application/json
  • (C) Authorization
  • (D) Accept
💬 Discuss
✅ Correct Answer: (B) Content-Type: application/json

Explanation: JSON content-type is set automatically.

📊 Trishul API
Q. What is a key design aspect of Response class?
  • (A) Instance-based properties
  • (B) Static properties
  • (C) Thread-safe variables
  • (D) Immutable design
💬 Discuss
✅ Correct Answer: (B) Static properties

Explanation: All properties are static.

📊 Trishul API
Q. What is a risk of using static properties in Response?
  • (A) Slow execution
  • (B) Memory leak
  • (C) Issues in concurrent environments
  • (D) Compilation error
💬 Discuss
✅ Correct Answer: (C) Issues in concurrent environments

Explanation: Shared state can cause concurrency issues.

📊 Trishul API
Q. When should headers and cookies be set?
  • (A) After out()
  • (B) Before out()
  • (C) After response sent
  • (D) Never
💬 Discuss
✅ Correct Answer: (B) Before out()

Explanation: Must be set before sending response.

📊 Trishul API
Q. What does Response::json() NOT do?
  • (A) Create response object
  • (B) Set status code
  • (C) Send response
  • (D) Set JSON header
💬 Discuss
✅ Correct Answer: (C) Send response

Explanation: json() does not send response.

📊 Trishul API
Q. What is correct usage to immediately return response?
Code:
Response::out(HttpStatus::OK, $data);
  • (A) Correct
  • (B) Incorrect - missing header
  • (C) Incorrect - wrong method
  • (D) Incorrect - wrong param
💬 Discuss
✅ Correct Answer: (A) Correct

Explanation: This sends response and terminates execution.

📊 Trishul API
Q. Which statement is true about Response class?
  • (A) Supports XML and JSON
  • (B) Only supports JSON currently
  • (C) Supports HTML rendering
  • (D) Supports binary responses
💬 Discuss
✅ Correct Answer: (B) Only supports JSON currently

Explanation: Currently JSON only.

📊 Trishul API
Q. What is the primary purpose of LoggerFactory?
  • (A) Handle database connections
  • (B) Provide logging mechanism
  • (C) Manage routing
  • (D) Handle middleware
💬 Discuss
✅ Correct Answer: (B) Provide logging mechanism

Explanation: LoggerFactory is used for logging application events.

📊 Trishul API
Q. Which method is used to set custom log directory?
  • (A) set_dir()
  • (B) set_log_dir()
  • (C) set_logs()
  • (D) set_path()
💬 Discuss
✅ Correct Answer: (B) set_log_dir()

Explanation: set_log_dir() defines where logs are stored.