Advanced University-Level PHP Exam Paper (Tough Level)

📝 Advanced PHP Exam Paper (Tough Level)

Subject: Advanced PHP Programming
Time: 3 Hours
Maximum Marks: 100


📘 Section A – Advanced MCQs (10 × 2 = 20 Marks)

  1. What will be the output?
$a = "10abc";
$b = 5;
echo $a + $b;

A) 15
B) 105
C) Error
D) 10abc5
✅ Answer: A


  1. Which function prevents SQL Injection?
    A) mysqli_query()
    B) htmlspecialchars()
    C) prepare() (PDO)
    D) echo()
    ✅ Answer: C

  1. What is the output?
var_dump([] == false);

A) true
B) false
C) error
D) null
✅ Answer: A


  1. Which is fastest output method?
    A) print
    B) echo
    C) printf
    D) var_dump
    ✅ Answer: B

  1. What is the scope of a static variable inside function?
    A) Global
    B) Local but retains value
    C) Block only
    D) Session
    ✅ Answer: B

  1. What does finally guarantee?
    A) Runs only if no error
    B) Runs always
    C) Runs on fatal error only
    D) Skips execution
    ✅ Answer: B

  1. Output?
echo "5" . 2 + 3;

A) 523
B) 10
C) 55
D) Error
✅ Answer: B


  1. Which handles fatal errors indirectly?
    A) try-catch
    B) set_error_handler()
    C) register_shutdown_function()
    D) error_reporting()
    ✅ Answer: C

  1. Which superglobal is immutable?
    A) $_POST
    B) $_GET
    C) $_SERVER
    D) None
    ✅ Answer: D

  1. What does strict_types=1 do?
    A) Converts types automatically
    B) Enforces strict type checking
    C) Disables errors
    D) Improves speed
    ✅ Answer: B

📗 Section B – Analytical Questions (5 × 4 = 20 Marks)

  1. Explain the difference between mysqli and PDO with real-world usage.
  2. Analyze:
if ("0" == false) echo "Yes";

Why does this happen?

  1. Explain how PHP handles type juggling with examples.
  2. What are closures in PHP? Give a real use case.
  3. Explain error vs exception vs throwable with hierarchy.

📙 Section C – Long Programming Questions (4 × 10 = 40 Marks)


✅ Q1. Build a secure login system with:

  • Password hashing
  • Session handling
  • Input validation

✅ Q2. Create a REST API in PHP:

  • Return JSON
  • Handle GET request
  • Include error handling

✅ Q3. Write a PHP script to:

  • Upload file
  • Validate type & size
  • Handle errors

✅ Q4. Create a custom error handling system:

  • Convert errors to exceptions
  • Log errors to file
  • Show user-friendly message

💻 Section D – Case Study (1 × 20 = 20 Marks)

🔥 Scenario:

Your PHP website is:

  • Showing white screen
  • Users report slow performance
  • Database queries sometimes fail

Questions:

  1. How will you debug the white screen issue?
  2. How will you optimize performance?
  3. How will you handle database failures?
  4. Suggest a complete error-handling strategy.

🏆 Bonus (Optional – 10 Marks)

Build a mini MVC structure in PHP:

  • Routing
  • Controller
  • View
  • Error handling

🎯 Examiner Expectations (High-Level)

  • Clean architecture (MVC mindset)
  • Secure coding (XSS, SQL Injection)
  • Proper error handling
  • Use of modern PHP (PDO, exceptions)
  • Real-world thinking

🔥 Difficulty Level

SectionLevel
MCQMedium
AnalyticalHard
CodingVery Hard
Case StudyExpert