PHP Interview Questions Hindi mein

PHP कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Modern PHP Foundations

1. What does PHP's shared-nothing model mean?

  1. Each request starts with fresh state, which is discarded when the request ends
  2. All requests share one global memory space
  3. PHP cannot use databases
  4. PHP runs only on one CPU core
जवाब देखें

जवाब: Each request starts with fresh state, which is discarded when the request ends

Request isolation keeps PHP simple to scale; persistent data lives in databases, caches or sessions.

पाठ: What PHP Is Today

2. Why should composer.lock be committed to version control for applications?

  1. It contains your source code
  2. Composer cannot run without Git
  3. It stores database passwords
  4. It pins exact dependency versions so every environment installs the same packages
जवाब देखें

जवाब: It pins exact dependency versions so every environment installs the same packages

The lock file makes installs reproducible across developers, CI and production.

पाठ: Running PHP: CLI, Built-in Server, php.ini and Composer

3. What does declare(strict_types=1) change?

  1. It makes all variables constant
  2. It disables arrays
  3. Calls from that file to typed functions throw TypeError instead of silently coercing scalar types
  4. It enables the JIT
जवाब देखें

जवाब: Calls from that file to typed functions throw TypeError instead of silently coercing scalar types

strict_types disables scalar coercion for calls made in that file.

पाठ: Syntax, Variables, Types and strict_types

Control Flow, Functions, Strings and Arrays

4. Which is true about match compared with switch?

  1. match compares loosely like ==
  2. match requires break statements
  3. match uses strict comparison, returns a value and does not fall through
  4. match cannot have a default arm
जवाब देखें

जवाब: match uses strict comparison, returns a value and does not fall through

match is a strict, expression-based alternative to switch.

पाठ: Control Flow and match

5. How does an arrow function access a variable from the surrounding scope?

  1. It cannot
  2. It captures it automatically by value
  3. Only with use (&$var)
  4. Only through global
जवाब देखें

जवाब: It captures it automatically by value

Arrow functions capture outer variables by value automatically; closures need an explicit use clause.

पाठ: Functions, Named Arguments and Closures

6. Why use mb_strlen instead of strlen for user-entered text in Hindi?

  1. strlen counts bytes, while mb_strlen counts characters in multibyte encodings such as UTF-8
  2. strlen is deprecated
  3. mb_strlen is faster for ASCII
  4. strlen only works on numbers
जवाब देखें

जवाब: strlen counts bytes, while mb_strlen counts characters in multibyte encodings such as UTF-8

UTF-8 characters can use several bytes, so byte counts differ from character counts.

पाठ: Strings and Arrays

Object-Oriented PHP

7. What does a readonly property guarantee in PHP 8.1+?

  1. It can be initialised once and not modified afterwards
  2. It can never be read
  3. It is static
  4. It is automatically serialised
जवाब देखें

जवाब: It can be initialised once and not modified afterwards

Readonly properties are write-once, making immutable objects straightforward.

पाठ: Classes, Constructor Promotion, Readonly and Enums

8. What does the #[\Override] attribute (PHP 8.3) do?

  1. It makes a method final
  2. It hides the parent method
  3. It enables traits
  4. It causes an error if the method does not actually override a parent or interface method
जवाब देखें

जवाब: It causes an error if the method does not actually override a parent or interface method

#[\Override] turns accidental non-overrides, such as typos, into errors.

पाठ: Inheritance, Interfaces, Abstract Classes and Traits

9. What does `public private(set) string $status` mean in PHP 8.4?

  1. The property is private for reading and writing
  2. The property is constant
  3. Anyone can read the property, but only the class itself can modify it
  4. It is a syntax error
जवाब देखें

जवाब: Anyone can read the property, but only the class itself can modify it

Asymmetric visibility separates read access from write access.

पाठ: Property Hooks, Asymmetric Visibility, Attributes and Magic Methods

Errors, Types and Code Organisation

10. Which class does a TypeError extend in PHP 8?

  1. Exception
  2. RuntimeException
  3. Error
  4. JsonException
जवाब देखें

जवाब: Error

TypeError is an Error, signalling an engine-level type problem, typically a bug.

पाठ: Exceptions and Error Handling

11. What does PHPStan or Psalm add on top of PHP's runtime type declarations?

  1. A faster interpreter
  2. Static checking of code, including docblock types such as array shapes and generics, without running it
  3. A web server
  4. Automatic database migrations
जवाब देखें

जवाब: Static checking of code, including docblock types such as array shapes and generics, without running it

Static analysers find type errors and bugs before the code runs.

पाठ: The Type System and Static Analysis

12. With PSR-4 mapping "Shop\\" to "src/", where should the class Shop\Orders\OrderService live?

  1. src/Orders/OrderService.php
  2. src/OrderService.php
  3. Shop/Orders.php
  4. vendor/Shop/OrderService.php
जवाब देखें

जवाब: src/Orders/OrderService.php

PSR-4 maps the namespace segments after the prefix onto directories under src/.

पाठ: Namespaces, Autoloading and Composer Packages

PHP on the Web

13. In a typical production setup, which component runs PHP code for NGINX?

  1. PHP-FPM via FastCGI
  2. Apache Tomcat
  3. Node.js
  4. The browser
जवाब देखें

जवाब: PHP-FPM via FastCGI

NGINX forwards PHP requests to PHP-FPM worker processes over FastCGI.

पाठ: The Request Lifecycle, PHP-FPM and Front Controllers

14. Why call session_regenerate_id(true) after a successful login?

  1. To log the user out
  2. To clear the shopping cart
  3. To speed up the session
  4. To issue a new session ID and prevent session fixation attacks
जवाब देखें

जवाब: To issue a new session ID and prevent session fixation attacks

A new ID ensures an attacker who planted or knew the old ID cannot hijack the authenticated session.

पाठ: Forms, Validation, Sessions and Cookies

15. How should passwords be stored in a PHP application?

  1. Plain text in the database
  2. As md5 hashes
  3. As hashes from password_hash(), checked with password_verify()
  4. Encrypted with a key stored in the same database
जवाब देखें

जवाब: As hashes from password_hash(), checked with password_verify()

password_hash uses slow, salted algorithms designed for passwords.

पाठ: Security: XSS, CSRF, SQL Injection and Passwords

Databases, JSON, HTTP and Files

16. Why do prepared statements prevent SQL injection?

  1. They encrypt the SQL
  2. They remove quotes from input
  3. The SQL structure and the data are sent separately, so data is never interpreted as SQL
  4. They only work with integers
जवाब देखें

जवाब: The SQL structure and the data are sent separately, so data is never interpreted as SQL

Bound parameters are always treated as values, never as SQL syntax.

पाठ: Databases with PDO

17. Which json_decode option makes invalid JSON throw an exception instead of returning null?

  1. JSON_PRETTY_PRINT
  2. JSON_THROW_ON_ERROR
  3. JSON_UNESCAPED_UNICODE
  4. JSON_FORCE_OBJECT
जवाब देखें

जवाब: JSON_THROW_ON_ERROR

JSON_THROW_ON_ERROR raises JsonException so failures cannot pass silently.

पाठ: JSON APIs and HTTP Clients

18. Why is DateTimeImmutable generally preferred over DateTime?

  1. Its methods return new objects instead of modifying the original, avoiding shared-state bugs
  2. It supports more time zones
  3. It is required for UTC
  4. It formats dates faster
जवाब देखें

जवाब: Its methods return new objects instead of modifying the original, avoiding shared-state bugs

Immutable date objects cannot be changed accidentally by other code.

पाठ: Files, Dates and Times

Standards, Frameworks and Testing

19. What does PSR-15 standardise?

  1. HTTP server request handlers and middleware
  2. Autoloading
  3. Logging
  4. Coding style
जवाब देखें

जवाब: HTTP server request handlers and middleware

PSR-15 defines MiddlewareInterface and RequestHandlerInterface.

पाठ: PHP-FIG Standards: PSRs and Coding Style

20. Which ORM is Laravel's default?

  1. Doctrine
  2. Hibernate
  3. Propel
  4. Eloquent
जवाब देखें

जवाब: Eloquent

Laravel ships with Eloquent, an active-record ORM; Symfony commonly uses Doctrine.

पाठ: Laravel and Symfony at a Glance

21. What is Rector used for?

  1. Serving HTTP requests
  2. Database migrations
  3. Automated refactoring and upgrading of PHP code
  4. Caching opcodes
जवाब देखें

जवाब: Automated refactoring and upgrading of PHP code

Rector rewrites code automatically, for example to adopt newer PHP syntax.

पाठ: Testing and Code Quality: PHPUnit, Pest, PHPStan and Rector

Performance, Deployment and Revision

22. What does OPcache do?

  1. Caches database query results
  2. Compresses HTTP responses
  3. Caches compiled opcodes in memory so scripts are not recompiled on each request
  4. Stores sessions
जवाब देखें

जवाब: Caches compiled opcodes in memory so scripts are not recompiled on each request

OPcache avoids repeated compilation, a major performance gain for every PHP application.

पाठ: Performance: OPcache, JIT and Profiling

23. Why install production dependencies with composer install --no-dev?

  1. It makes tests run faster
  2. It leaves out development tools such as PHPUnit, reducing size and attack surface
  3. It updates all packages to the latest versions
  4. It is required by PHP-FPM
जवाब देखें

जवाब: It leaves out development tools such as PHPUnit, reducing size and attack surface

Development dependencies are not needed in production and add unnecessary code.

पाठ: Deployment and Configuration

24. Which practice belongs to modern PHP?

  1. Prepared statements with PDO and strict types
  2. Using mysql_* functions
  3. Hashing passwords with md5
  4. Suppressing errors with @
जवाब देखें

जवाब: Prepared statements with PDO and strict types

Prepared statements and strict types are core modern practices; the others are outdated and unsafe.

पाठ: Legacy PHP Versus Modern PHP

25. Which feature lets you declare and assign properties directly in the constructor signature?

  1. Traits
  2. Magic methods
  3. Late static binding
  4. Constructor property promotion
जवाब देखें

जवाब: Constructor property promotion

Constructor promotion (PHP 8.0) combines property declaration and assignment.

पाठ: Revision and Interview Questions

← कोर्स पर वापस जाएँ