PHP Questions
1. PHP stands for:
A. Private Home Page
B. Preprocessor Hypertext Protocol
C. PHP: Hypertext Preprocessor
D. Programmable HTML Processor
C. PHP: Hypertext Preprocessor
2. What is the correct way to open a PHP code block?
A. <php>
B. <?php
C. <script php>
D. <?php?>
B. <?php
3. How are variables declared in PHP?
A. Using the var
keyword
B. With a $
symbol (e.g., $variable
)
C. With the let
keyword
D. Variables are automatically declared
B. With a $
symbol (e.g., $variable
)
4. Which is NOT a scalar data type in PHP?
A. integer
B. float
C. string
D. array
D. array
5. How are constants defined in PHP?
A. define(“CONSTANT”, value)
B. const CONSTANT = value
C. Both a and b
D. Using $constant
C. Both a and b
6. Which superglobal holds POST request data?
A. $_GET
B. $_POST
C. $_REQUEST
D. $_SERVER
B. $_POST
7. Which directive enables all error reporting?
A. error_reporting(0)
B. error_reporting(E_ALL)
C. hide_errors(1)
D. display_errors(false)
B. error_reporting(E_ALL)
8. What is the difference between include and require?
A. require continues execution if file is missing
B. include emits a warning if file is missing
C. require cannot include PHP files
D. No difference
B. include emits a warning if file is missing
9. How do you start a session in PHP?
A. session_start()
B. start_session()
C. $_SESSION->init()
D. Sessions start automatically
A. session_start()
10. How are cookies set in PHP?
A. set_cookie()
B. setcookie()
C. $_COOKIE->set()
D. Using HTML <cookie> tag
B. setcookie()
11. Which keyword declares a class in PHP?
A. function
B. class
C. object
D. new
B. class
12. In PHP, the constructor method is named:
A. __init()
B. __construct()
C. _constructor()
D. Class()
B. __construct()
13. How is inheritance implemented in PHP?
A. Using implements
B. Using extends
C. With inherit keyword
D. Via traits
B. Using extends
14. Interfaces in PHP are declared with:
A. abstract class
B. interface
C. trait
D. protocol
B. interface
15. Traits are used for:
A. Horizontal code reuse
B. Replacing interfaces
C. Creating objects directly
D. Error handling
A. Horizontal code reuse
16. What is the advantage of PDO over mysql_* functions?
A. Database abstraction and security
B. Faster execution
C. Only works with MySQL
D. No prepared statements
A. Database abstraction and security
17. Prepared statements help prevent:
A. SQL injection
B. CSS attacks
C. PHP syntax errors
D. Infinite loops
A. SQL injection
18. Composer is a PHP:
A. Framework
B. Dependency manager
C. Alternative syntax
D. Debugging tool
B. Dependency manager
19. Namespaces prevent:
A. Naming collisions
B. All errors
C. Variable declarations
D. Class inheritance
A. Naming collisions
20. Which is NOT a PHP framework?
A. Laravel
B. Symfony
C. Django
D. CodeIgniter
C. Django