MPSeDC GET Program 3.0 2026 – Exam-Oriented PHP MCQ Questions

MPSeDC GET Program 3.0 2026 – Exam-Oriented PHP MCQ Questions

Beginner Level MCQs (30 Questions)

Q1. Which keyword is used to define a class in PHP?
Conceptual
(A) class
(B) Class
(C) define class
(D) object


Correct Answer: (A)
Explanation: PHP uses the lowercase keyword ‘class’ to declare a class, e.g. class Student { }. PHP keywords are case-insensitive but convention uses lowercase.
Exam Shortcut / Memory Trick: Remember: PHP class = lowercase ‘class’ keyword, just like Java/C++

Q2. Which symbol is used to access members (properties/methods) of an object in PHP?
Conceptual
(A) ::
(B) ->
(C) .
(D) #


Correct Answer: (B)
Explanation: The arrow operator -> is used to access properties and methods of an instantiated object. :: (scope resolution) is used for static members.
Exam Shortcut / Memory Trick: -> for OBJECT, :: for STATIC/CLASS (think ‘arrow points to instance’).


Q3. Which operator is used to access static properties or methods in PHP OOP?
Conceptual
(A) ->
(B) ::
(C) =>
(D) ..


Correct Answer: (B)
Explanation: The Scope Resolution Operator (::) is used to access static, constant, and overridden properties/methods of a class without instantiating it.
Exam Shortcut / Memory Trick: ‘:: ‘ = Static/Class access (‘Scope’). ‘->’ = instance access.


Q4. What is the correct way to create an object of class ‘Employee’ in PHP?
Conceptual
(A) $e = new Employee();
(B) $e = create Employee();
(C) Employee e = new Employee();
(D) object $e = Employee();


Correct Answer: (A)
Explanation: PHP objects are instantiated using the ‘new’ keyword followed by the class name and parentheses: $e = new Employee();
Exam Shortcut / Memory Trick: new ClassName() — exactly like Java syntax.


Q5. Which magic method is automatically called when an object is created?
(A) __construct()
(B) __create()
(C) init()
(D) __new()


Correct Answer: (A)

Explanation: __construct() is the constructor magic method, automatically invoked when an object is instantiated, used to initialize properties.
Exam Shortcut / Memory Trick: Construct = ‘build at start’ → constructor runs first.


Q6. Which magic method is called automatically when an object is destroyed?
(A) __destruct()
(B) __delete()
(C) __remove()
(D) __unset()


Correct Answer: (A)

Explanation: __destruct() is called when an object has no more references or at script end, used for cleanup tasks like closing connections.
Exam Shortcut / Memory Trick: destruct = opposite of construct.

Q7. Which of the following is NOT a pillar of Object-Oriented Programming?
(A) Encapsulation
(B) Polymorphism
(C) Compilation
(D) Inheritance


Correct Answer: (C)

Explanation: The four pillars of OOP are Encapsulation, Inheritance, Polymorphism, and Abstraction. Compilation is not an OOP concept.
Exam Shortcut / Memory Trick: Remember ‘A PIE’: Abstraction, Polymorphism, Inheritance, Encapsulation.

Q8. Which PHP access modifier allows a property to be accessed only within the declaring class?
(A) public
(B) protected
(C) private
(D) static


Correct Answer: (C)

Explanation: private restricts access strictly to the class in which it is defined; not accessible to child classes or outside code.
Exam Shortcut / Memory Trick: private = personal, only the class itself can use it.

Q9. Which access modifier allows access within the class and its child (derived) classes?
(A) private
(B) protected
(C) public
(D) final


Correct Answer: (B)

Explanation: protected members are accessible within the declaring class and any subclasses (inheritance chain), but not from outside code.
Exam Shortcut / Memory Trick: protected = family access (parent + child classes).

Q10. Which access modifier allows access from anywhere?
(A) private
(B) protected
(C) public
(D) internal


Correct Answer: (C)

Explanation: public members can be accessed from inside the class, subclasses, and outside the class — fully open access.
Exam Shortcut / Memory Trick: public = open to all, no restrictions.

Q11. In PHP, which keyword is used for inheritance?
(A) implements
(B) extends
(C) inherits
(D) derives


Correct Answer: (B)

Explanation: PHP uses ‘extends’ for class inheritance: class Child extends Parent {}. ‘implements’ is used for interfaces.
Exam Shortcut / Memory Trick: extends = class-to-class, implements = class-to-interface.

Q12. What is encapsulation in OOP?
(A) Hiding implementation details and exposing only necessary parts
(B) Creating multiple objects
(C) Using loops inside classes
(D) Compiling code faster


Correct Answer: (A)

Explanation: Encapsulation means bundling data (properties) and methods together while restricting direct access to internal details using access modifiers, exposing controlled interfaces (getters/setters).
Exam Shortcut / Memory Trick: Encapsulation = ‘capsule’ that hides internal data.

Q13. What is abstraction in OOP?
(A) Showing only essential features and hiding complexity
(B) Combining many classes
(C) Repeating code
(D) Declaring variables


Correct Answer: (A)

Explanation: Abstraction focuses on exposing only relevant/essential information to the user while hiding internal implementation complexity, often via abstract classes/interfaces.
Exam Shortcut / Memory Trick: Abstraction = blueprint, hides ‘how’, shows ‘what’.

Q14. Which keyword declares a constant property of a class in PHP?
(A) const
(B) define
(C) final
(D) static


Correct Answer: (A)

Explanation: The ‘const’ keyword inside a class defines a class constant, e.g., const PI = 3.14; accessed via ClassName::PI.
Exam Shortcut / Memory Trick: const inside class = fixed value, accessed via ::

Q15. How do you refer to the current object instance inside a class method in PHP?
(A) this
(B) self
(C) $this
(D) current


Correct Answer: (C)

Explanation: $this is a pseudo-variable referring to the calling object within non-static methods.
Exam Shortcut / Memory Trick: $this = ‘this’ object, only in non-static context.

Q16. Which keyword refers to the class itself (not the instance), commonly used for static members?
(A) $this
(B) self
(C) parent
(D) static (only)


Correct Answer: (B)

Explanation: self:: refers to the class in which it’s used, mainly for accessing static properties/methods/constants.
Exam Shortcut / Memory Trick: self = self’s own class definition, not the runtime object.

Q17. Which keyword is used to call a parent class’s constructor or method from a child class?
(A) super
(B) base
(C) parent
(D) extends


Correct Answer: (C)

Explanation: parent:: is used inside a child class to call the parent class’s constructor or overridden methods, e.g., parent::__construct();
Exam Shortcut / Memory Trick: PHP has no ‘super’ keyword like Java — use parent:: instead.

Q18. What does MVC stand for?
(A) Model View Controller
(B) Model Variable Class
(C) Multiple View Class
(D) Method View Component


Correct Answer: (A)

Explanation: MVC stands for Model-View-Controller, a design pattern separating application logic into three interconnected components.
Exam Shortcut / Memory Trick: M-V-C = Data(Model) – UI(View) – Logic(Controller).

Q19. In MVC architecture, which component is responsible for database interaction?
(A) View
(B) Controller
(C) Model
(D) Router


Correct Answer: (C)

Explanation: The Model handles data logic — interacting with the database, performing validation, and business rules.
Exam Shortcut / Memory Trick: Model = ‘manages’ data/DB.

Q20. In MVC, which component handles presentation/UI to the user?
(A) Model
(B) View
(C) Controller
(D) Library


Correct Answer: (B)

Explanation: The View is responsible for rendering the user interface and displaying data passed from the controller.
Exam Shortcut / Memory Trick: View = what user ‘views’ (HTML output).

Q21. In MVC, which component receives user requests and coordinates Model and View?
(A) Model
(B) View
(C) Controller
(D) Helper


Correct Answer: (C)

Explanation: The Controller acts as an intermediary, receiving input/requests, invoking Model operations, and selecting the View to render.
Exam Shortcut / Memory Trick: Controller = ‘controls’ the flow between Model and View.

Q22. Which of the following is a PHP MVC framework?
(A) jQuery
(B) CodeIgniter
(C) Bootstrap
(D) AJAX


Correct Answer: (B)

Explanation: CodeIgniter is a lightweight PHP framework following the MVC architectural pattern. jQuery/Bootstrap are front-end libraries, AJAX is a technique.
Exam Shortcut / Memory Trick: CI & Laravel = PHP MVC frameworks; jQuery/Bootstrap = front-end tools.

Q23. Which command is used to create a new Laravel project via Composer?
(A) laravel new project
(B) composer create-project laravel/laravel project
(C) php laravel install
(D) npm install laravel


Correct Answer: (B)

Explanation: Laravel projects are typically created using Composer: composer create-project laravel/laravel project-name, or via the Laravel installer ‘laravel new’.
Exam Shortcut / Memory Trick: Composer = PHP’s package manager, used to scaffold Laravel.

Q24. Which file in CodeIgniter (3.x) is used to set base configuration like base_url?
(A) routes.php
(B) config.php
(C) database.php
(D) autoload.php


Correct Answer: (B)

Explanation: application/config/config.php holds core configuration settings such as base_url, encryption key, and session settings.
Exam Shortcut / Memory Trick: config.php = the ‘settings file’ of CodeIgniter.

Q25. In Laravel, which folder contains the route definition files?
(A) app/Routes
(B) routes/
(C) config/routes
(D) public/routes


Correct Answer: (B)

Explanation: Laravel stores route files (web.php, api.php, console.php) inside the routes/ directory at the project root.
Exam Shortcut / Memory Trick: routes/web.php = main web route file.

Q26. Which SQL statement is used to retrieve data from a MySQL table?
(A) GET
(B) FETCH
(C) SELECT
(D) SHOW


Correct Answer: (C)

Explanation: The SELECT statement is used to query and retrieve rows/columns of data from one or more tables.
Exam Shortcut / Memory Trick: SELECT = Read operation in CRUD.

Q27. Which SQL clause is used to filter rows based on a condition?
(A) ORDER BY
(B) WHERE
(C) GROUP BY
(D) HAVING


Correct Answer: (B)

Explanation: WHERE filters rows before grouping, based on specified conditions, e.g., SELECT * FROM emp WHERE salary > 5000;
Exam Shortcut / Memory Trick: WHERE = filter individual rows.

Q28. Which MySQL data type is used to store variable-length string data efficiently?
(A) CHAR
(B) VARCHAR
(C) TEXT only
(D) INT


Correct Answer: (B)

Explanation: VARCHAR stores variable-length strings up to a specified limit, using only as much storage as needed (plus length prefix).
Exam Shortcut / Memory Trick: VAR-char = VARiable length character.

Q29. Which PHP function connects to a MySQL database using MySQLi in object-oriented style?
(A) mysqli_connect()
(B) new mysqli()
(C) mysql_connect()
(D) db_connect()


Correct Answer: (B)

Explanation: In OOP style, ‘new mysqli(host, user, pass, db)’ creates a connection object. mysqli_connect() is the procedural equivalent.
Exam Shortcut / Memory Trick: new mysqli(…) = OOP style; mysqli_connect() = procedural style.

Q30. Which PHP extension/library is recommended for secure, prepared-statement based database access supporting multiple DBMS?
(A) mysql_* (old)
(B) mysqli
(C) PDO
(D) curl


Correct Answer: (C)

Explanation: PDO (PHP Data Objects) provides a consistent interface for accessing multiple database systems and supports prepared statements for security; mysqli is MySQL-specific.
Exam Shortcut / Memory Trick: PDO = Portable Data Objects, works across DB types (MySQL, PostgreSQL, SQLite…).

Intermediate Level MCQs (40 Questions)

Q31. Which OOP concept allows a child class to provide a specific implementation of a method already defined in its parent class?
(A) Overloading
(B) Overriding
(C) Encapsulation
(D) Abstraction


Correct Answer: (B)

Explanation: Method Overriding occurs when a subclass redefines a method with the same name and signature as in its parent class, replacing the parent’s behavior.
Exam Shortcut / Memory Trick: Override = ‘ride over’ the parent’s version.

Q32. Does PHP natively support traditional method overloading (same method name, different parameter lists) like Java/C++?
(A) Yes, fully supported
(B) No, PHP uses magic methods __call/__callStatic to simulate it
(C) Yes, but only for static methods
(D) No, PHP doesn’t allow multiple methods at all


Correct Answer: (B)

Explanation: PHP does not support compile-time method overloading. Instead, dynamic ‘overloading’ is simulated using magic methods like __call() and __callStatic() to handle calls to inaccessible/undefined methods.
Exam Shortcut / Memory Trick: PHP overloading ≠ Java overloading; PHP uses __call() magic trick.

Q33. Which keyword prevents a class from being inherited or a method from being overridden?
(A) static
(B) final
(C) abstract
(D) const


Correct Answer: (B)

Explanation: The ‘final’ keyword, when applied to a class, prevents inheritance; applied to a method, prevents overriding in child classes.
Exam Shortcut / Memory Trick: final = ‘the end’, no further extension allowed.

Q34. Which type of class cannot be instantiated directly and may contain abstract methods?
(A) Interface
(B) Abstract class
(C) Final class
(D) Static class


Correct Answer: (B)

Explanation: An abstract class (declared with ‘abstract class’) cannot be instantiated; it can contain both abstract (unimplemented) and concrete methods, meant to be extended.
Exam Shortcut / Memory Trick: abstract = incomplete blueprint, must be extended to use.

Q35. What is the key difference between an abstract class and an interface in PHP?
(A) Interfaces can have constructors, abstract classes cannot
(B) Abstract class can have method implementations; interface methods are all abstract (must be implemented)
(C) Interfaces support multiple inheritance of implementation
(D) No difference


Correct Answer: (B)

Explanation: An abstract class can have a mix of implemented and abstract methods plus properties, while an interface only declares method signatures (a contract) without implementation, and a class can implement multiple interfaces.
Exam Shortcut / Memory Trick: Abstract class = partial blueprint; Interface = pure contract, no body.

Q36. How many interfaces can a single PHP class implement?
(A) Only one
(B) Multiple, using comma-separated list with ‘implements’
(C) Zero
(D) Only two


Correct Answer: (B)

Explanation: PHP supports implementing multiple interfaces using ‘implements Interface1, Interface2 {…}’, even though PHP allows only single class inheritance via extends.
Exam Shortcut / Memory Trick: PHP: single class inheritance, but MULTIPLE interface implementation.

Q37. What does polymorphism mean in OOP?
(A) One interface, many implementations/forms
(B) Hiding data
(C) Multiple inheritance
(D) Creating constants


Correct Answer: (A)

Explanation: Polymorphism allows objects of different classes to be treated through a common interface, with each providing its own behavior — e.g., overridden methods behaving differently per subclass.
Exam Shortcut / Memory Trick: Poly = many, morph = forms → ‘many forms’.

Q38. What will be the output?
class A { function show() { echo “A”; } }
class B extends A { function show() { echo “B”; } }
$obj = new B();
$obj->show();
(A) A
(B) B
(C) AB
(D) Error


Correct Answer: (B)

Explanation: Since B overrides show(), calling $obj->show() on a B instance invokes B’s version, printing ‘B’. This demonstrates method overriding/polymorphism.
Exam Shortcut / Memory Trick: Child’s overridden method always wins when called on child object.

Q39. What is the output?
class Counter {
public static $count = 0;
function __construct() { self::$count++; }
}
new Counter(); new Counter(); new Counter();
echo Counter::$count;
(A) 0
(B) 1
(C) 3
(D) Error


Correct Answer: (C)

Explanation: static properties are shared across all instances. Each constructor call increments the shared $count, resulting in 3 after three instantiations.
Exam Shortcut / Memory Trick: static property = shared counter across ALL objects.

Q40. Identify the error:
class Demo {
private $name;
function __construct($n) { $this->name = $n; }
}
$d = new Demo(“Test”);
echo $d->name;
(A) No error, prints Test
(B) Fatal error: Cannot access private property
(C) Warning only, prints nothing
(D) Notice: undefined property


Correct Answer: (B)

Explanation: nameisdeclaredprivate,soitcannotbeaccesseddirectlyfromoutsidetheclass.PHPthrowsaFatalError:CannotaccessprivatepropertyDemo::name is declared private, so it cannot be accessed directly from outside the class. PHP throws a Fatal Error: Cannot access private property Demo::nameisdeclaredprivate,soitcannotbeaccesseddirectlyfromoutsidetheclass.PHPthrowsaFatalError:CannotaccessprivatepropertyDemo::name.
Exam Shortcut / Memory Trick: private property → must use a public getter method to access from outside.

Q41. Fix the bug: A child class method is supposed to call its parent’s constructor but nothing happens.
class Animal { function __construct() { echo “Animal created”; } }
class Dog extends Animal { function __construct() { echo “Dog created”; } }
(A) It’s correct as is
(B) Add parent::__construct(); inside Dog’s constructor
(C) Remove Dog’s constructor entirely
(D) Use self::__construct() instead


Correct Answer: (B)

Explanation: When a child class defines its own constructor, the parent constructor is NOT called automatically. You must explicitly call parent::__construct(); to invoke it.
Exam Shortcut / Memory Trick: Child constructor overrides parent’s — call parent::__construct() explicitly if needed.

Q42. In MVC, what is ‘routing’ primarily responsible for?
(A) Styling the view
(B) Mapping URLs to specific controller actions
(C) Connecting to the database
(D) Validating form inputs only


Correct Answer: (B)

Explanation: Routing maps incoming URL requests to the appropriate controller and method (action) that should handle them, central to both CodeIgniter and Laravel.
Exam Shortcut / Memory Trick: Router = ‘traffic signal’ directing URL → Controller method.

Q43. A developer wants to keep business logic out of controllers in a Laravel app to follow best practice. Where should this be placed?
(A) Directly inside Blade views
(B) In Service classes / Repository pattern (or Models)
(C) In routes/web.php
(D) In the public/index.php file


Correct Answer: (B)

Explanation: Best practice (fat models/thin controllers or service layer) suggests moving business logic into Models, Service classes, or Repositories, keeping Controllers focused on request handling/coordination.
Exam Shortcut / Memory Trick: ‘Fat Model, Skinny Controller’ principle.

Q44. In CodeIgniter, which directory typically contains controller files?
(A) application/models
(B) application/views
(C) application/controllers
(D) application/config


Correct Answer: (C)

Explanation: CodeIgniter (2.x/3.x) organizes MVC under application/, with controllers stored in application/controllers/.
Exam Shortcut / Memory Trick: controllers folder = where request-handling PHP classes live.

Q45. In Laravel, which Artisan command generates a new controller?
(A) php artisan make:model
(B) php artisan make:controller
(C) php artisan controller:new
(D) php artisan generate:controller


Correct Answer: (B)

Explanation: php artisan make:controller ControllerName creates a new controller class inside app/Http/Controllers.
Exam Shortcut / Memory Trick: ‘make:X’ is Artisan’s generic generator pattern.

Q46. In Laravel, what is Eloquent?
(A) A templating engine
(B) An Object-Relational Mapping (ORM) system
(C) A routing component
(D) A CSS framework


Correct Answer: (B)

Explanation: Eloquent is Laravel’s built-in ORM that lets developers interact with database tables using PHP objects/models instead of raw SQL.
Exam Shortcut / Memory Trick: Eloquent = Laravel’s ORM (Object talks to DB rows).

Q47. Which Eloquent method retrieves all records of a model?
(A) Model::find()
(B) Model::all()
(C) Model::get(1)
(D) Model::first(all)


Correct Answer: (B)

Explanation: Model::all() returns a collection of all rows from the model’s associated table.
Exam Shortcut / Memory Trick: all() = SELECT * FROM table; equivalent.

Q48. Given Eloquent: User::where(‘age’, ‘>’, 18)->get(); — what does this return?
(A) A single User object
(B) A Collection of User objects matching age > 18
(C) An array of ages
(D) A boolean


Correct Answer: (B)

Explanation: ->get() executes the query and returns an Eloquent Collection containing all matching User model instances.
Exam Shortcut / Memory Trick: get() = many results as a Collection; first()/find() = single result.

Q49. Which Blade syntax is used to echo a variable safely (escaped) in Laravel views?
(A) <?php echo $var; ?>
(B) {{ $var }}
(C) {!! $var !!}
(D) #$var#


Correct Answer: (B)

Explanation: {{ $var }} automatically escapes output using htmlspecialchars to prevent XSS; {!! !!} prints raw unescaped HTML.
Exam Shortcut / Memory Trick: {{ }} = safe/escaped, {!! !!} = raw/unsafe.

Q50. In CodeIgniter, which design helps load a Model inside a Controller?
(A) $this->load->model(‘ModelName’)
(B) $this->import(‘ModelName’)
(C) include ‘ModelName’
(D) new Model()


Correct Answer: (A)

Explanation: CodeIgniter uses $this->load->model(‘Model_name’) to load and instantiate a model, accessible thereafter as $this->Model_name.
Exam Shortcut / Memory Trick: $this->load->X() = CI’s universal loader for model/view/library/helper.

Q51. Which CodeIgniter function is used to load a view file?
(A) $this->load->view(‘viewname’)
(B) $this->render(‘viewname’)
(C) include_view(‘viewname’)
(D) $this->view->load()


Correct Answer: (A)

Explanation: $this->load->view(‘filename’, $data) loads a view file from application/views, optionally passing data to it.
Exam Shortcut / Memory Trick: load->view() = render HTML output in CI.

Q52. Which Laravel migration command applies pending migrations to the database?
(A) php artisan migrate
(B) php artisan db:update
(C) php artisan migration:run
(D) php artisan schema:apply


Correct Answer: (A)

Explanation: php artisan migrate runs all pending migration files, creating/altering database tables as defined in the migration classes.
Exam Shortcut / Memory Trick: migrate = apply schema changes to DB.

Q53. What is the purpose of Laravel migrations?
(A) To migrate users between servers
(B) To version-control database schema changes using PHP code
(C) To migrate Laravel versions
(D) To backup the database


Correct Answer: (B)

Explanation: Migrations are like version control for your database, allowing schema definitions (tables, columns) to be defined in PHP and shared/applied across environments.
Exam Shortcut / Memory Trick: Migration = ‘Git for database schema’.

Q54. Which SQL JOIN returns only matching rows from both tables?
(A) LEFT JOIN
(B) RIGHT JOIN
(C) INNER JOIN
(D) FULL OUTER JOIN


Correct Answer: (C)

Explanation: INNER JOIN returns rows where there is a match in both joined tables based on the join condition; non-matching rows are excluded.
Exam Shortcut / Memory Trick: INNER = ‘common area’ (intersection) of two tables.

Q55. Which JOIN returns all rows from the left table, and matched rows (or NULLs) from the right table?
(A) INNER JOIN
(B) LEFT JOIN
(C) RIGHT JOIN
(D) CROSS JOIN


Correct Answer: (B)

Explanation: LEFT JOIN (LEFT OUTER JOIN) returns all records from the left table, with NULLs for non-matching rows in the right table.
Exam Shortcut / Memory Trick: LEFT JOIN = keep everything from LEFT table.

Q56. Which SQL clause groups rows sharing a property so aggregate functions can be applied per group?
(A) WHERE
(B) GROUP BY
(C) ORDER BY
(D) JOIN


Correct Answer: (B)

Explanation: GROUP BY groups rows with identical values in specified columns, typically used with aggregate functions like COUNT(), SUM(), AVG().
Exam Shortcut / Memory Trick: GROUP BY = bucket rows together for aggregation.

Q57. Which clause is used to filter groups AFTER a GROUP BY (instead of WHERE)?
(A) WHERE
(B) HAVING
(C) FILTER
(D) WHEN


Correct Answer: (B)

Explanation: HAVING filters grouped results based on aggregate conditions (e.g., HAVING COUNT(*) > 5), whereas WHERE filters rows before grouping.
Exam Shortcut / Memory Trick: WHERE = before grouping, HAVING = after grouping.

Q58. Which PHP database access feature helps prevent SQL Injection by separating SQL logic from data?
(A) String concatenation
(B) Prepared Statements
(C) echo statements
(D) Global variables


Correct Answer: (B)

Explanation: Prepared statements (via PDO or mysqli) pre-compile SQL queries with placeholders, binding user input as data (not executable code), thus preventing SQL Injection.
Exam Shortcut / Memory Trick: Prepared statement = ‘fill-in-the-blank’ query, data never becomes code.

Q59. What is the issue with this code?$id = $_GET[‘id’];
$query = “SELECT * FROM users WHERE id = $id”;
result=mysqliquery(result = mysqli_query(result=mysqliq​uery(conn, $query);
(A) No issue, valid PHP
(B) Vulnerable to SQL Injection
(C) Syntax error
(D) It won’t connect to DB


Correct Answer: (B)

Explanation: Directly embedding unsanitized user input ($_GET[‘id’]) into a raw SQL string makes this code vulnerable to SQL Injection attacks. A prepared statement should be used instead.
Exam Shortcut / Memory Trick: Any raw GET/_GET/G​ET/_POST inside SQL string = instant SQL Injection red flag.

Q60. Fix this PDO code to prevent SQL Injection:stmt = $pdo->query(“SELECT * FROM users WHERE email = ‘ email'”);
(A) Use mysqli instead
(B) Use $pdo->prepare() with bound parameters/placeholders
(C) Use addslashes() only
(D) No fix needed


Correct Answer: (B)

Explanation: Replace direct query() with prepare() and bind parameters: stmt = $pdo->prepare(‘SELECT * FROM users WHERE email = ?’); $stmt->execute([ email]); This neutralizes injection risk.
Exam Shortcut / Memory Trick: Always: prepare() + bindParam()/execute([…]) for user input.

Q61. What does CSRF protection in Laravel primarily guard against?
(A) SQL Injection
(B) Cross-Site Request Forgery attacks via forged form submissions
(C) Cross-Site Scripting
(D) Server downtime


Correct Answer: (B)

Explanation: Laravel automatically generates CSRF tokens (@csrf in Blade forms) to verify that form submissions originate from the application itself, preventing forged cross-site requests.
Exam Shortcut / Memory Trick: CSRF = unauthorized request from another site using user’s session; token verifies authenticity.

Q62. In Laravel, which component validates incoming HTTP request data easily within a controller?
(A) $request->validate([…]) method or Form Request classes
(B) Blade directives
(C) Artisan migrate
(D) Service Providers


Correct Answer: (A)

Explanation: Laravel provides $request->validate([‘field’ => ‘rules’]) in controllers, or dedicated Form Request classes, to validate and automatically redirect on failure.
Exam Shortcut / Memory Trick: validate() = built-in Laravel request validator.

Q63. What is Composer in the context of PHP frameworks like Laravel?
(A) A code editor
(B) A dependency/package manager for PHP
(C) A database management tool
(D) A templating engine


Correct Answer: (B)

Explanation: Composer is PHP’s dependency manager, used to install and autoload libraries/packages (including Laravel itself) defined in composer.json.
Exam Shortcut / Memory Trick: Composer = PHP’s npm equivalent.

Q64. Which file defines a Laravel/PHP project’s dependencies managed by Composer?
(A) package.json
(B) composer.json
(C) requirements.txt
(D) autoload.php


Correct Answer: (B)

Explanation: composer.json lists project dependencies, autoloading rules, and metadata; composer.lock locks exact installed versions.
Exam Shortcut / Memory Trick: composer.json (PHP) vs package.json (Node).

Q65. Which namespace keyword helps avoid class name conflicts across files in PHP?
(A) package
(B) namespace
(C) module
(D) using


Correct Answer: (B)

Explanation: PHP’s ‘namespace’ keyword groups related classes/functions/constants under a unique name to avoid collisions, e.g., namespace App\Models;
Exam Shortcut / Memory Trick: namespace = folder-like grouping to prevent name clashes.

Q66. Which keyword imports a namespaced class for use without specifying its full path each time?
(A) import
(B) include
(C) use
(D) require


Correct Answer: (C)

Explanation: The ‘use’ keyword imports a namespace/class so it can be referenced by its short name, e.g., use App\Models\User;
Exam Shortcut / Memory Trick: use = PHP’s ‘import’ for namespaces.

Q67. What is Dependency Injection, commonly used in Laravel’s service container?
(A) Manually creating every object inside a class
(B) Supplying a class’s dependencies from outside rather than creating them internally
(C) Injecting SQL into queries
(D) A type of database join


Correct Answer: (B)

Explanation: Dependency Injection (DI) is a design pattern where an object’s dependencies are provided externally (often via constructor), promoting loose coupling and testability.
Exam Shortcut / Memory Trick: DI = ‘give’, don’t ‘make’ — dependencies are passed in, not created inside.

Q68. In Laravel routing, which HTTP verb-based route method handles a GET request?
(A) Route::post()
(B) Route::get()
(C) Route::put()
(D) Route::delete()


Correct Answer: (B)

Explanation: Route::get(‘/uri’, callback) registers a route responding to GET requests; similarly post(), put(), delete() exist for other verbs.
Exam Shortcut / Memory Trick: Route::VERB() directly maps to the HTTP method name.

Q69. Which CodeIgniter component handles reusable utility functions like form validation or string manipulation NOT tied to a specific model/class structure?
(A) Controllers
(B) Helpers
(C) Views
(D) Hooks


Correct Answer: (B)

Explanation: Helpers in CodeIgniter are collections of standalone functions (e.g., form_helper, url_helper) loaded via $this->load->helper(‘name’) to assist with common tasks.
Exam Shortcut / Memory Trick: Helper = simple function toolbox, not a class.

Q70. Why is the MVC pattern preferred for large-scale web applications?
(A) It makes apps slower
(B) It separates concerns, improving maintainability, testability, and parallel development
(C) It removes the need for databases
(D) It eliminates the need for a web server


Correct Answer: (B)

Explanation: MVC separates data (Model), UI (View), and logic (Controller), enabling cleaner code organization, easier maintenance, reusability, and parallel team development.
Exam Shortcut / Memory Trick: MVC = Separation of Concerns → maintainable, testable, scalable code.

Advanced Level MCQs (31 Questions)

Q71. Which design principle states that a class should have only one reason to change?
(A) Open/Closed Principle
(B) Single Responsibility Principle
(C) Liskov Substitution Principle
(D) Dependency Inversion Principle


Correct Answer: (B)

Explanation: The Single Responsibility Principle (SRP), one of the SOLID principles, states a class should have only one job/responsibility, reducing coupling and easing maintenance.
Exam Shortcut / Memory Trick: SRP = ‘Single’ job per class.

Q72. Which SOLID principle states software entities should be open for extension but closed for modification?
(A) Single Responsibility
(B) Open/Closed Principle
(C) Interface Segregation
(D) Liskov Substitution


Correct Answer: (B)

Explanation: The Open/Closed Principle means you should be able to extend a class’s behavior (e.g., via inheritance/interfaces) without modifying its existing source code.
Exam Shortcut / Memory Trick: Open for extension (add new), Closed for modification (don’t touch old code).

Q73. What is the output?
abstract class Shape {
abstract public function area();
public function info() { echo “Area: ” . $this->area(); }
}
class Square extends Shape {
private $side;
function __construct($s) { $this->side = $s; }
public function area() { return $this->side * $this->side; }
}
$s = new Square(4);
$s->info();
(A) Area: 16
(B) Area: 8
(C) Error: cannot instantiate
(D) Area: 4


Correct Answer: (A)

Explanation: info() calls $this->area(), which resolves to Square’s implementation, computing 4*4=16, printing ‘Area: 16’.
Exam Shortcut / Memory Trick: Abstract method calls inside parent are resolved using the CHILD’s implementation at runtime.

Q74. What is ‘Late Static Binding’ in PHP, triggered by the ‘static::’ keyword?
(A) Binding variables at compile time
(B) A mechanism to reference the called class in static context (resolved at runtime) rather than the class where the method is defined
(C) A type of database binding
(D) A way to bind static properties to instances


Correct Answer: (B)

Explanation: Late Static Binding (static::) resolves to the class that was actually called at runtime, unlike self:: which always refers to the class where it’s literally written.
Exam Shortcut / Memory Trick: self:: = where written; static:: = who called it.

Q75. What is the output?
class Base {
public static function create() { return new static(); }
public function name() { return get_class($this); }
}
class Derived extends Base {}
echo Derived::create()->name();
(A) Base
(B) Derived
(C) Error
(D) Static


Correct Answer: (B)

Explanation: ‘new static()’ uses late static binding, so when called via Derived::create(), it instantiates Derived (not Base). get_class returns ‘Derived’.
Exam Shortcut / Memory Trick: new static() = instantiate the ACTUALLY called class.

Q76. Which magic method is triggered when accessing an inaccessible (private/protected) or non-existing property?
(A) __get()
(B) __set()
(C) __call()
(D) __invoke()


Correct Answer: (A)

Explanation: __get($name) is automatically invoked when reading data from inaccessible or undefined properties, commonly used to implement custom getters.
Exam Shortcut / Memory Trick: __get = ‘get’ inaccessible property; pairs with __set for writing.

Q77. Which magic method allows an object to be called as if it were a function, e.g., $obj()?
(A) __call()
(B) __invoke()
(C) __toString()
(D) __set()


Correct Answer: (B)

Explanation: __invoke() is triggered when a script tries to call an object as a function, e.g., obj(obj(obj(args), enabling callable objects.
Exam Shortcut / Memory Trick: __invoke = makes object ‘invokable’ like a function.

Q78. Which magic method converts an object to a string automatically (e.g., when echoed)?
(A) __toString()
(B) __string()
(C) __print()
(D) __display()


Correct Answer: (A)

Explanation: __toString() defines what is returned when an object is treated as a string, such as echo $obj; — must return a string.
Exam Shortcut / Memory Trick: echo $obj → triggers __toString() automatically.

Q79. Which keyword combination allows a class to use methods from multiple sources, working around PHP’s single inheritance limitation?
(A) Multiple extends
(B) Traits (use keyword)
(C) Interfaces only
(D) Namespaces


Correct Answer: (B)

Explanation: PHP Traits (declared with ‘trait’ and included via ‘use TraitName;’ inside a class) allow horizontal code reuse, letting a class ‘mix in’ methods from multiple traits.
Exam Shortcut / Memory Trick: Traits = ‘copy-paste’ reusable method sets across unrelated classes.

Q80. What happens?
trait Hello { public function sayHello() { echo “Hello “; } }
trait World { public function sayWorld() { echo “World”; } }
class Greeting { use Hello, World; }
$g = new Greeting();
$g->sayHello();
$g->sayWorld();
(A) Error: cannot use multiple traits
(B) Outputs ‘Hello World’
(C) Outputs ‘World Hello’
(D) Outputs only ‘Hello’


Correct Answer: (B)

Explanation: A class can use multiple traits via ‘use Hello, World;’, gaining both sayHello() and sayWorld() methods, producing ‘Hello World’.
Exam Shortcut / Memory Trick: use Trait1, Trait2; = combine multiple traits’ methods into one class.

Q81. What is the N+1 query problem commonly encountered with Eloquent ORM?
(A) Running 1 query then N additional queries for related models due to lazy loading instead of eager loading
(B) A database with N+1 tables
(C) A syntax error in SQL
(D) An overflow error


Correct Answer: (A)

Explanation: N+1 problem occurs when fetching N parent records then looping and lazily loading related data triggers N extra queries. Solved using eager loading, e.g., User::with(‘posts’)->get();
Exam Shortcut / Memory Trick: Fix N+1: use ->with(‘relation’) for eager loading instead of accessing relation in a loop.

Q82. A Laravel app shows slow performance: fetching 100 Posts then accessing $post->author->name in a loop causes 101 queries. What is the best fix?
(A) Add more RAM
(B) Use eager loading: Post::with(‘author’)->get();
(C) Use raw SQL only
(D) Switch to CodeIgniter


Correct Answer: (B)

Explanation: This is a classic N+1 problem. Using Post::with(‘author’)->get() eager-loads the author relationship in a single additional query, drastically reducing query count.
Exam Shortcut / Memory Trick: Eager loading (with()) collapses N+1 queries into just 2 queries.

Q83. What is the purpose of Laravel’s Service Container?
(A) To style components
(B) To manage class dependencies and perform dependency injection
(C) To handle CSS/JS bundling
(D) To run migrations


Correct Answer: (B)

Explanation: Laravel’s Service Container (IoC container) is a powerful tool for managing class dependencies and performing dependency injection automatically.
Exam Shortcut / Memory Trick: Service Container = Laravel’s ‘auto-wiring’ dependency resolver.

Q84. What are Laravel Middleware used for?
(A) Database migrations
(B) Filtering HTTP requests entering the application (e.g., authentication checks)
(C) Styling Blade templates
(D) Defining Eloquent relationships


Correct Answer: (B)

Explanation: Middleware act as filters/layers around HTTP requests, e.g., ‘auth’ middleware checks if a user is authenticated before allowing access to a route.
Exam Shortcut / Memory Trick: Middleware = checkpoint/gate a request passes through before reaching the controller.

Q85. In Eloquent, which relationship method is used when one Post belongsTo one User (e.g., post’s author)?
(A) hasMany()
(B) belongsTo()
(C) belongsToMany()
(D) hasOne()


Correct Answer: (B)

Explanation: belongsTo() defines an inverse one-to-many (or one-to-one) relationship — used on the model that holds the foreign key, e.g., Post belongsTo User via user_id.
Exam Shortcut / Memory Trick: belongsTo = the side WITH the foreign key column.

Q86. Which Eloquent relationship method defines a many-to-many relationship requiring a pivot table?
(A) hasMany()
(B) belongsTo()
(C) belongsToMany()
(D) hasOneThrough()


Correct Answer: (C)

Explanation: belongsToMany() defines many-to-many relationships, relying on an intermediate pivot table (e.g., role_user) to link two models.
Exam Shortcut / Memory Trick: belongsToMany = many-to-many, needs a pivot table.

Q87. What does the ‘hasMany’ relationship represent in Eloquent, e.g., User hasMany Posts?
(A) One User belongs to many Posts (foreign key on User)
(B) One User can have multiple Post records (foreign key on Posts table)
(C) Many Users share one Post
(D) A pivot table relationship


Correct Answer: (B)

Explanation: hasMany() indicates the current model (User) can be associated with multiple records of another model (Posts), where the foreign key (user_id) resides on the related (Posts) table.
Exam Shortcut / Memory Trick: hasMany = ‘parent’ side; foreign key lives on the ‘many’ (child) table.

Q88. Identify the bug:class Singleton {
private static $instance;
public function __construct() {}
public static function getInstance() {
if (self::instance==null)self::instance == null) self::instance==null)self::instance = new Singleton();
return self::$instance;
}
}
(A) No bug, valid Singleton
(B) Constructor should be private to enforce Singleton pattern
(C) getInstance should be non-static
(D) static $instance is invalid syntax


Correct Answer: (B)

Explanation: A true Singleton must have a private (or protected) constructor to prevent external code from creating new instances directly via ‘new Singleton()’, bypassing the pattern.
Exam Shortcut / Memory Trick: Singleton checklist: private constructor + private static instance + public static getInstance().

Q89. Which design pattern does Eloquent’s Model class itself partially represent, mapping each table row to an object?
(A) Factory Pattern
(B) Active Record Pattern
(C) Observer Pattern
(D) Strategy Pattern


Correct Answer: (B)

Explanation: Eloquent follows the Active Record pattern, where each model instance represents a row, and the model class itself contains methods to interact with its corresponding database table (save, delete, query).
Exam Shortcut / Memory Trick: Active Record = the object ‘is’ the row and knows how to save/delete itself.

Q90. Which Laravel feature allows automatically firing events when a model is created, updated, or deleted (e.g., for logging)?
(A) Eloquent Observers / Model Events
(B) Middleware
(C) Service Providers only
(D) Blade Components


Correct Answer: (A)

Explanation: Eloquent Observers (or model event hooks like creating, created, updating, deleted) let you hook custom logic into the model’s lifecycle events without cluttering controllers.
Exam Shortcut / Memory Trick: Observers = listen for model lifecycle events.

Q91. What is the primary purpose of database transactions (BEGIN, COMMIT, ROLLBACK) in MySQL?
(A) To speed up SELECT queries
(B) To ensure a group of operations either fully succeed or fully fail (atomicity)
(C) To create indexes automatically
(D) To back up the database


Correct Answer: (B)

Explanation: Transactions group multiple SQL statements so they execute as a single atomic unit: if any statement fails, ROLLBACK undoes all changes; otherwise COMMIT makes them permanent.
Exam Shortcut / Memory Trick: Transactions = ‘all or nothing’ execution (ACID – Atomicity).

Q92. Which ACID property ensures that once a transaction is committed, it remains so even after a system crash?
(A) Atomicity
(B) Consistency
(C) Isolation
(D) Durability


Correct Answer: (D)

Explanation: Durability guarantees committed transactions survive system failures, typically achieved via write-ahead logging or persistent storage.
Exam Shortcut / Memory Trick: Durability = ‘durable/permanent’ once committed.

Q93. Which MySQL storage engine supports foreign keys and transactions (default in modern MySQL)?
(A) MyISAM
(B) InnoDB
(C) MEMORY
(D) ARCHIVE


Correct Answer: (B)

Explanation: InnoDB is the default MySQL storage engine supporting ACID transactions, foreign key constraints, and row-level locking, unlike MyISAM which lacks transaction/FK support.
Exam Shortcut / Memory Trick: InnoDB = transactions + foreign keys; MyISAM = neither.

Q94. Which type of index automatically exists on a MySQL table’s PRIMARY KEY column?
(A) No index by default
(B) A unique clustered index (in InnoDB)
(C) A full-text index
(D) A bitmap index


Correct Answer: (B)

Explanation: In InnoDB, the PRIMARY KEY is implemented as a clustered index, meaning the table data is physically stored in primary key order, enabling fast lookups.
Exam Shortcut / Memory Trick: PRIMARY KEY in InnoDB = automatic clustered index.

Q95. What is database normalization primarily intended to achieve?
(A) Faster hardware performance
(B) Reducing data redundancy and improving data integrity by organizing tables/relationships
(C) Encrypting data
(D) Increasing table count for no reason


Correct Answer: (B)

Explanation: Normalization is the process of structuring relational tables to minimize redundancy and dependency issues, typically achieved through normal forms (1NF, 2NF, 3NF, etc.).
Exam Shortcut / Memory Trick: Normalization = eliminate duplicate/redundant data via proper table design.

Q96. Which normal form requires that a table has no transitive dependency (non-key attributes depend only on the primary key)?
(A) 1NF
(B) 2NF
(C) 3NF
(D) BCNF


Correct Answer: (C)

Explanation: Third Normal Form (3NF) requires the table be in 2NF and that all non-key attributes are non-transitively dependent on the primary key.
Exam Shortcut / Memory Trick: 3NF = ‘no transitive dependency’ — non-key fields depend ONLY on the key.

Q97. Which command in MySQL is used to create a relationship by referencing the primary key of another table?
(A) PRIMARY KEY
(B) FOREIGN KEY … REFERENCES
(C) UNIQUE KEY
(D) CHECK


Correct Answer: (B)

Explanation: FOREIGN KEY (column) REFERENCES other_table(column) enforces referential integrity by linking a column to a primary/unique key in another table.
Exam Shortcut / Memory Trick: FOREIGN KEY … REFERENCES = the ‘link’ between two related tables.

Q98. In a Laravel e-commerce app, multiple stock-update and order-insert queries must succeed together or not at all when an order is placed. What should the developer use?
(A) Separate independent queries with no transaction
(B) DB::transaction(function () { … }) wrapping all related queries
(C) Run queries in a loop only
(D) Use raw file storage instead of DB


Correct Answer: (B)

Explanation: Wrapping related write operations in DB::transaction(closure) ensures atomicity — if any query inside fails, Laravel automatically rolls back all changes, maintaining data consistency.
Exam Shortcut / Memory Trick: Multiple dependent writes → ALWAYS wrap in DB::transaction() in Laravel.

Q99. Which Laravel artisan command generates a migration, model, controller, and resource routes together quickly?
(A) php artisan make:model ModelName -mcr
(B) php artisan quick:setup
(C) php artisan generate:all
(D) php artisan scaffold


Correct Answer: (A)

Explanation: php artisan make:model ModelName -mcr creates a Model plus its Migration (-m), Controller (-c), and Resource controller methods (-r) in one command.
Exam Shortcut / Memory Trick: -mcr flags = Migration + Controller + Resource, attached to make:model.

Q100. What does Laravel’s ‘php artisan tinker’ command do?
(A) Compiles assets
(B) Opens an interactive REPL/console to test PHP and Eloquent code directly
(C) Runs unit tests
(D) Clears cache


Correct Answer: (B)

Explanation: Tinker provides an interactive shell (REPL) where developers can execute PHP code, query Eloquent models, and test logic directly without writing a full script.
Exam Shortcut / Memory Trick: Tinker = Laravel’s interactive PHP console.

Q101. Why is it generally recommended to use an ORM like Eloquent instead of raw SQL queries in large applications?
(A) ORMs are always faster than SQL
(B) ORMs provide abstraction, security (prepared statements), maintainability, and database portability, though raw SQL may still be used for complex queries
(C) Raw SQL is deprecated
(D) ORMs eliminate the need for databases


Correct Answer: (B)

Explanation: ORMs like Eloquent abstract database interactions into object-oriented code, automatically use prepared statements, improve readability/maintainability, and ease switching between DB drivers.
Exam Shortcut / Memory Trick: ORM trade-off: convenience & security vs. raw control & performance for complex queries.

MPSeDC GET Program 3.0 2026 – Exam-Oriented PHP MCQ Questions
Scroll to top