MCQs  On Class 40
Real-World Project - Part 2 (Concept)
1-10: General PHP Project Completion
1.   Which of the following is the first step when completing a real-world PHP project?
o    A) Debugging the code
o    B) Writing test cases
o    C) Reviewing project features
o    D) Setting up the project environment
Answer: D) Setting up the project environment
2.   What does CRUD stand for in PHP?
o    A) Create, Read, Update, Delete
o    B) Control, Read, Update, Debug
o    C) Create, Repeat, Undo, Delete
o    D) Class, Run, Upload, Delete
Answer: A) Create, Read, Update, Delete
3.   Which method is commonly used to handle forms in PHP?
o    A) POST
o    B) GET
o    C) PUT
o    D) PATCH
Answer: A) POST
4.   Which of the following is NOT a PHP feature when developing a real-world project?
o    A) Handling form submissions
o    B) Connecting to a database
o    C) Writing HTML pages manually
o    D) Implementing security features
Answer: C) Writing HTML pages manually
5.   Which function is used to hash passwords securely in PHP?
o    A) hash()
o    B) password_hash()
o    C) encrypt_password()
o    D) secure_password()
Answer: B) password_hash()
6.   What does password_verify() do in PHP?
o    A) Verifies the login email
o    B) Verifies that the user entered the correct password
o    C) Verifies the length of the password
o    D) Verifies whether the password matches the stored hashed password
Answer: D) Verifies whether the password matches the stored hashed password
7.   Which method should you use to prevent SQL injection in PHP?
o    A) Use mysqli_query()
o    B) Use prepared statements with bound parameters
o    C) Use mysql_query() directly
o    D) Use $_GET to retrieve input
Answer: B) Use prepared statements with bound parameters
8.   Which of the following is a recommended way to store sensitive information like passwords in a database?
o    A) Plain text
o    B) Base64 encoded
o    C) Hashed and salted
o    D) Encrypted with the AES algorithm
Answer: C) Hashed and salted
9.   In PHP, how do you handle user input to prevent Cross-Site Scripting (XSS) attacks?
o    A) Use htmlspecialchars()
o    B) Use sanitize() function
o    C) Remove all special characters
o    D) Ignore user input
Answer: A) Use htmlspecialchars()
10.                     Which of the following is the most effective method for ensuring secure session management?
- A) Store sensitive data in cookies
 - B) Use session_regenerate_id() after login
 - C) Use session_destroy() at the start of the session
 - D) Set session cookies with a 10-year expiry date
Answer: B) Use session_regenerate_id() after login 
11-20: Project Features and Functionality
11.                     What is the purpose of implementing a login feature in a PHP-based project?
- A) To track user sessions
 - B) To validate email addresses
 - C) To allow multiple users to access the site simultaneously
 - D) To manage user credentials and authentication
Answer: D) To manage user credentials and authentication 
12.                     When adding an admin feature to a PHP project, what is the primary concern?
- A) Admin should have full access to all functionalities
 - B) Admin should be able to view the website’s content
 - C) Admin should only have access to CRUD operations on users
 - D) Admin should not have login privileges
Answer: A) Admin should have full access to all functionalities 
13.                     Which SQL statement is used to retrieve data from a database in PHP?
- A) SELECT
 - B) INSERT
 - C) UPDATE
 - D) DELETE
Answer: A) SELECT 
14.                     Which PHP function is used to escape special characters in a string to prevent SQL injection?
- A) mysqli_real_escape_string()
 - B) sql_escape()
 - C) prepare()
 - D) escape_string()
Answer: A) mysqli_real_escape_string() 
15.                     What is the purpose of a session in PHP?
- A) To store permanent data on the client-side
 - B) To store temporary data that can be accessed across multiple pages
 - C) To generate random numbers for testing
 - D) To log user activity
Answer: B) To store temporary data that can be accessed across multiple pages 
16.                     In PHP, which of the following is used to redirect a user to a different page?
- A) header()
 - B) redirect()
 - C) go_to()
 - D) jump()
Answer: A) header() 
17.                     Which PHP function would you use to check if a user is logged in before granting access to a page?
- A) session_status()
 - B) isset()
 - C) session_start()
 - D) isset($_SESSION['user_id'])
Answer: D) isset($_SESSION['user_id']) 
18.                     What does a "CRUD" system typically refer to in PHP?
- A) File handling
 - B) Database operations
 - C) Form validation
 - D) Session management
Answer: B) Database operations 
19.                     Which method would you use to prevent users from submitting empty fields in a PHP form?
- A) JavaScript validation
 - B) isset() function
 - C) HTML required attribute
 - D) Both B and C
Answer: D) Both B and C 
20.                     Which of the following PHP functions is used to validate an email address?
- A) validate_email()
 - B) email_check()
 - C) filter_var()
 - D) check_email()
Answer: C) filter_var() 
21-30: Security and Optimization
21.                     What is the purpose of sanitizing user input in PHP?
- A) To make sure the input is converted to a string
 - B) To remove unwanted characters that could lead to security vulnerabilities
 - C) To format the input for storage
 - D) To prevent the server from processing input
Answer: B) To remove unwanted characters that could lead to security vulnerabilities 
22.                     How can you improve the performance of a PHP query that retrieves multiple records from a database?
- A) Use LIMIT to reduce the number of records
 - B) Use SELECT * instead of specifying columns
 - C) Avoid using indexes
 - D) Avoid using prepared statements
Answer: A) Use LIMIT to reduce the number of records 
23.                     Which PHP function is used to close a database connection?
- A) db_close()
 - B) mysqli_close()
 - C) close_db()
 - D) mysqli_end()
Answer: B) mysqli_close() 
24.                     When should you use session_start() in PHP?
- A) Before any HTML output
 - B) After the login page
 - C) After creating a session variable
 - D) In the footer section
Answer: A) Before any HTML output 
25.                     Which of the following methods will help protect against XSS (Cross-Site Scripting) in PHP?
- A) Encrypt all form inputs
 - B) Escape special HTML characters using htmlspecialchars()
 - C) Use mysqli_real_escape_string()
 - D) Avoid using forms
Answer: B) Escape special HTML characters using htmlspecialchars() 
26.                     Which of the following should be used to store sensitive information, such as passwords, in a database?
- A) Base64 encoding
 - B) Hashing with salt
 - C) Plain text
 - D) Encryption
Answer: B) Hashing with salt 
27.                     Which function should be used to validate user-provided input in PHP forms?
- A) check_input()
 - B) is_valid()
 - C) filter_var()
 - D) sanitize_input()
Answer: C) filter_var() 
28.                     What is the role of mysqli_fetch_assoc() in PHP?
- A) To retrieve data from a session
 - B) To fetch a row of results as an associative array
 - C) To execute SQL queries
 - D) To close the database connection
Answer: B) To fetch a row of results as an associative array 
29.                     Which HTTP status code represents a successful form submission in PHP?
- A) 400
 - B) 404
 - C) 200
 - D) 500
Answer: C) 200 
30.                     What would you use PHP’s filter_var() function for in a form?
- A) To sanitize user input
 - B) To validate user input
 - C) To filter HTML content
 - D) All of the above
Answer: D) All of the above 
31-40: Error Handling and Debugging
31.                     What is the purpose of error_reporting() in PHP?
- A) To suppress all errors
 - B) To control which types of errors are displayed
 - C) To log errors to a file
 - D) To debug SQL queries
Answer: B) To control which types of errors are displayed 
32.                     Which of the following would you use to display error messages for debugging in PHP?
- A) error_reporting(E_ALL);
 - B) echo error_report();
 - C) log_errors_on();
 - D) show_errors();
Answer: A) error_reporting(E_ALL); 
33.                     In PHP, how can you display all PHP errors for debugging purposes?
- A) Use error_reporting(E_ALL);
 - B) Use ini_set('display_errors', 1);
 - C) Both A and B
 - D) Use debug_errors(true);
Answer: C) Both A and B 
34.                     What is a common debugging tool used in PHP?
- A) Xdebug
 - B) Firebug
 - C) Console.log
 - D) Browser Developer Tools
Answer: A) Xdebug 
35.                     Which of the following functions can be used to log errors in PHP?
- A) error_log()
 - B) log_error()
 - C) debug_log()
 - D) record_error()
Answer: A) error_log() 
36.                     What does PHP’s ini_set() function do?
- A) It controls the PHP error settings
 - B) It initializes a session
 - C) It sets the database configuration
 - D) It creates a new PHP configuration file
Answer: A) It controls the PHP error settings 
37.                     How do you handle errors in PHP without showing them to the user?
- A) Use error_reporting(0)
 - B) Use try/catch block
 - C) Set display_errors to Off
 - D) All of the above
Answer: D) All of the above 
38.                     What is the result of setting display_errors to Off in PHP?
- A) Errors will be hidden from the user
 - B) Errors will be logged to a file
 - C) Only warnings will be displayed
 - D) All errors will stop
Answer: A) Errors will be hidden from the user 
39.                     Which PHP function is used to generate a unique identifier for a session?
- A) session_unique()
 - B) session_id()
 - C) session_regenerate_id()
 - D) generate_session()
Answer: C) session_regenerate_id() 
40.                     Which of the following is recommended for production environments regarding error reporting?
- A) Turn off error display but log errors
 - B) Display all errors
 - C) Turn off error logging
 - D) Display warnings only
Answer: A) Turn off error display but log errors 
41-50: Final Project Considerations
41.                     Which of the following best defines a “final project review” in a real-world PHP application?
- A) A code cleanup to ensure readability
 - B) A check for all essential features
 - C) A performance and security audit
 - D) All of the above
Answer: D) All of the above 
42.                     What is one of the final steps in completing a PHP project before deployment?
- A) Committing code to version control
 - B) Ensuring all comments are removed
 - C) Writing an application documentation
 - D) Testing all edge cases
Answer: C) Writing an application documentation 
43.                     What should be done before deploying a PHP application to production?
- A) Run the application in a staging environment
 - B) Change all passwords
 - C) Remove all test cases
 - D) Disable security features
Answer: A) Run the application in a staging environment 
44.                     What is the purpose of a staging environment in PHP development?
- A) To deploy the live version of the application
 - B) To test the project with real users
 - C) To simulate a production environment for final testing
 - D) To host the development version of the project
Answer: C) To simulate a production environment for final testing 
45.                     Which of the following is important to verify before the production release of a PHP application?
- A) Ensure it is free of errors and warnings
 - B) Confirm all functionality works as expected
 - C) Perform load and stress testing
 - D) All of the above
Answer: D) All of the above 
46.                     What is the best way to handle database migrations when deploying PHP applications?
- A) Manually update the database
 - B) Use a version control system for database changes
 - C) Ignore database changes
 - D) Use temporary tables
Answer: B) Use a version control system for database changes 
47.                     What should be done to secure a PHP application before deployment?
- A) Install SSL certificates
 - B) Ensure proper user role management
 - C) Sanitize and validate user input
 - D) All of the above
Answer: D) All of the above 
48.                     Which tool is commonly used to deploy PHP applications in real-world projects?
- A) GitHub
 - B) FTP clients
 - C) Jenkins
 - D) All of the above
Answer: D) All of the above 
49.                     What is the purpose of version control in PHP development?
- A) To track changes and manage code collaboration
 - B) To manage database migrations
 - C) To automatically deploy the application
 - D) To automate testing
Answer: A) To track changes and manage code collaboration 
50.                     Which of the following is a useful tool for handling PHP errors in production?
- A) Firebug
 - B) Xdebug
 - C) PHP error logs
 - D) GitHub
Answer: C) PHP error logs 
51-60: Maintenance and Updates
51.                     What should be done regularly after deploying a PHP project to production?
- A) Monitor performance and security
 - B) Update the PHP version
 - C) Check for security patches
 - D) All of the above
Answer: D) All of the above 
52.                     How often should you perform updates on a live PHP application?
- A) Only when there is a major bug
 - B) When a new PHP version is released
 - C) On a scheduled basis for security and performance
 - D) Never after the initial deployment
Answer: C) On a scheduled basis for security and performance 
53.                     Which of the following is an example of ongoing maintenance for a PHP project?
- A) Updating PHP packages
 - B) Responding to user feedback
 - C) Adding new features
 - D) All of the above
Answer: D) All of the above 
54.                     How should security vulnerabilities be addressed in a PHP application after deployment?
- A) Apply patches promptly
 - B) Ignore the vulnerabilities
 - C) Wait for a major release
 - D) Redesign the entire application
Answer: A) Apply patches promptly 
55.                     What is the role of a “bug tracking system” in a PHP project?
- A) To track errors and security issues
 - B) To manage project tasks
 - C) To track feature requests
 - D) All of the above
Answer: D) All of the above 
56.                     What is essential for the long-term success of a PHP application?
- A) Regularly updating the codebase
 - B) Ensuring that it is optimized for search engines
 - C) Adding unnecessary features
 - D) Ensuring it is only used internally
Answer: A) Regularly updating the codebase 
57.                     How can a PHP project be improved for better scalability?
- A) Optimize database queries
 - B) Use a Content Delivery Network (CDN)
 - C) Use caching mechanisms
 - D) All of the above
Answer: D) All of the above 
58.                     What is the benefit of using automated testing in PHP development?
- A) Ensures code is tested continuously
 - B) Reduces the need for manual testing
 - C) Helps identify issues early in development
 - D) All of the above
Answer: D) All of the above 
59.                     What is the importance of documentation in a PHP project?
- A) Helps developers understand the code structure
 - B) Assists in troubleshooting issues
 - C) Ensures that new developers can join the project smoothly
 - D) All of the above
Answer: D) All of the above 
60.                     Which of the following is important when working on a team PHP project?
- A) Properly commenting the code
 - B) Regularly pushing changes to a version control system
 - C) Following coding standards
 - D) All of the above
Answer: D) All of the above 
61-70: Deployment and Hosting
61.                     What is the first step to take when preparing to deploy a PHP project to a server?
- A) Install PHP on the server
 - B) Write documentation for the project
 - C) Ensure the codebase is properly versioned
 - D) Test the application on localhost
Answer: C) Ensure the codebase is properly versioned 
62.                     Which hosting service is commonly used for deploying PHP applications?
- A) WordPress Hosting
 - B) Bluehost
 - C) Netlify
 - D) DigitalOcean
Answer: B) Bluehost 
63.                     Which of the following PHP configuration files is important for setting environment variables in production?
- A) php.ini
 - B) .env file
 - C) index.php
 - D) config.php
Answer: B) .env file 
64.                     What is the purpose of using a composer.json file in a PHP project?
- A) To store database credentials
 - B) To list project dependencies
 - C) To configure session settings
 - D) To log application errors
Answer: B) To list project dependencies 
65.                     When should you switch from a staging to a production environment in PHP development?
- A) When the application is fully tested and error-free
 - B) After code optimization
 - C) After setting up version control
 - D) When all database connections are configured
Answer: A) When the application is fully tested and error-free 
66.                     Which server-side language is commonly used with PHP in a LAMP stack?
- A) Python
 - B) Ruby
 - C) Apache
 - D) Node.js
Answer: C) Apache 
67.                     What is the importance of SSL/TLS in a PHP application deployment?
- A) It ensures secure data transmission
 - B) It improves the website’s loading speed
 - C) It reduces the server load
 - D) It simplifies database configurations
Answer: A) It ensures secure data transmission 
68.                     Which of the following is necessary for deploying PHP on a server with HTTPS?
- A) SSL certificate
 - B) Apache server configuration
 - C) PHP version 7 or higher
 - D) MySQL database
Answer: A) SSL certificate 
69.                     Which of the following is a recommended practice when deploying a PHP application?
- A) Leave the development configuration on the production server
 - B) Disable display of errors in production
 - C) Keep passwords in the source code
 - D) Ignore database backups
Answer: B) Disable display of errors in production 
70.                     What is the use of htaccess file in a PHP project deployment?
- A) To store environment variables
 - B) To configure server redirects and rewrites
 - C) To manage user authentication
 - D) To list PHP dependencies
Answer: B) To configure server redirects and rewrites 
71-80: Security Best Practices
71.                     Which of the following PHP functions should be used to prevent SQL Injection?
- A) mysqli_query()
 - B) mysqli_real_escape_string()
 - C) sql_fetch()
 - D) mysql_fetch_assoc()
Answer: B) mysqli_real_escape_string() 
72.                     What is the purpose of using prepared statements in PHP when interacting with a database?
- A) To increase query performance
 - B) To prevent SQL injection
 - C) To store data in sessions
 - D) To enhance server security
Answer: B) To prevent SQL injection 
73.                     What is a common method to store passwords securely in a PHP application?
- A) Plaintext
 - B) MD5 hashing
 - C) bcrypt hashing
 - D) Base64 encoding
Answer: C) bcrypt hashing 
74.                     Which function in PHP should be used to check if a file is uploaded securely?
- A) is_uploaded_file()
 - B) move_uploaded_file()
 - C) file_exists()
 - D) fopen()
Answer: A) is_uploaded_file() 
75.                     What is the purpose of the session_start() function in PHP?
- A) To start a session on the server for user authentication
 - B) To send headers to the client
 - C) To open a connection to the database
 - D) To validate user input
Answer: A) To start a session on the server for user authentication 
76.                     Which of the following is an effective way to prevent Cross-Site Scripting (XSS) attacks in PHP?
- A) Using the htmlspecialchars() function
 - B) Using password_hash()
 - C) Sanitizing input data with filter_var()
 - D) Disabling cookies
Answer: A) Using the htmlspecialchars() function 
77.                     What does the csrf_token() function in Laravel or similar frameworks prevent?
- A) SQL Injection
 - B) Cross-Site Request Forgery (CSRF) attacks
 - C) Cross-Site Scripting (XSS)
 - D) Session Hijacking
Answer: B) Cross-Site Request Forgery (CSRF) attacks 
78.                     Which of the following is the best practice to protect sensitive data in PHP?
- A) Store it in plaintext
 - B) Encrypt it using a secure algorithm
 - C) Save it in a cookie
 - D) Store it in a log file
Answer: B) Encrypt it using a secure algorithm 
79.                     What is the benefit of using a Web Application Firewall (WAF) with PHP applications?
- A) To block malicious requests and enhance security
 - B) To optimize PHP execution time
 - C) To manage database migrations
 - D) To improve SEO
Answer: A) To block malicious requests and enhance security 
80.                     What is the most secure way to store session data in PHP?
- A) Store it in cookies
 - B) Store it in files with appropriate file permissions
 - C) Store it in a public directory
 - D) Store it in a plaintext database
Answer: B) Store it in files with appropriate file permissions 
81-90: Performance Optimization
81.                     Which of the following techniques can improve the performance of a PHP application?
- A) Using caching mechanisms like Memcached
 - B) Writing inefficient SQL queries
 - C) Avoiding the use of any framework
 - D) Ignoring error handling
Answer: A) Using caching mechanisms like Memcached 
82.                     What does PHP’s opcache do for performance?
- A) It compresses the PHP files
 - B) It caches compiled PHP bytecode in memory
 - C) It monitors for code changes
 - D) It speeds up database connections
Answer: B) It caches compiled PHP bytecode in memory 
83.                     Which PHP function should be used to measure the execution time of a script?
- A) microtime()
 - B) execution_time()
 - C) gettimeofday()
 - D) memory_usage()
Answer: A) microtime() 
84.                     What is the best way to optimize database queries in PHP?
- A) Use complex joins for every query
 - B) Minimize the number of queries by using batch processing
 - C) Use SELECT * in all queries
 - D) Avoid indexing the database
Answer: B) Minimize the number of queries by using batch processing 
85.                     What is the primary purpose of using a Content Delivery Network (CDN) with a PHP application?
- A) To store PHP code
 - B) To distribute static content like images and scripts across multiple servers
 - C) To run PHP scripts in multiple regions
 - D) To speed up database queries
Answer: B) To distribute static content like images and scripts across multiple servers 
86.                     Which PHP function is used to open a persistent database connection?
- A) mysqli_connect()
 - B) mysqli_pconnect()
 - C) pdo_connect()
 - D) persistent_db_connect()
Answer: B) mysqli_pconnect() 
87.                     What is one method to reduce the memory footprint of a PHP application?
- A) Use multiple include statements
 - B) Optimize the use of global variables
 - C) Use unset() to destroy variables when they are no longer needed
 - D) Always store variables in session
Answer: C) Use unset() to destroy variables when they are no longer needed 
88.                     Which PHP function is used to execute an SQL query with a prepared statement?
- A) mysql_query()
 - B) mysqli_execute()
 - C) mysqli_query()
 - D) mysqli_prepare()
Answer: B) mysqli_execute() 
89.                     Which PHP configuration setting can help reduce execution time for scripts?
- A) max_execution_time
 - B) memory_limit
 - C) display_errors
 - D) log_errors
Answer: A) max_execution_time 
90.                     How can you handle large file uploads efficiently in PHP?
- A) Increase the upload_max_filesize and post_max_size in php.ini
 - B) Allow unlimited file sizes in the configuration
 - C) Use JavaScript for file uploads only
 - D) Disable file uploads entirely
Answer: A) Increase the upload_max_filesize and post_max_size in php.ini 
91-100: Debugging, Testing, and Documentation
91.                     What is the purpose of using var_dump() in PHP?
- A) To test the functionality of a database
 - B) To print detailed information about a variable, including its data type and value
 - C) To execute a database query
 - D) To format the output of an HTML page
Answer: B) To print detailed information about a variable, including its data type and value 
92.                     Which of the following is the best tool for debugging PHP code?
- A) echo statements
 - B) Xdebug
 - C) var_dump()
 - D) print_r()
Answer: B) Xdebug 
93.                     Which of the following PHP functions is used to handle errors gracefully in an application?
- A) try-catch block
 - B) trigger_error()
 - C) error_log()
 - D) All of the above
Answer: D) All of the above 
94.                     What does PHPUnit allow you to do in PHP?
- A) Write unit tests for your code
 - B) Monitor performance of PHP scripts
 - C) Handle errors in your code
 - D) Secure PHP applications
Answer: A) Write unit tests for your code 
95.                     Which of the following is NOT a valid PHP testing tool?
- A) PHPUnit
 - B) Behat
 - C) Selenium
 - D) PhpStorm
Answer: D) PhpStorm 
96.                     What is the purpose of writing comments in PHP code?
- A) To improve the performance of the code
 - B) To make the code easier to understand for other developers
 - C) To make the code run faster
 - D) To hide errors in the code
Answer: B) To make the code easier to understand for other developers 
97.                     Which PHP function can be used to prevent direct access to a PHP file by users?
- A) exit()
 - B) die()
 - C) header()
 - D) include()
Answer: C) header() 
98.                     What is the purpose of a README.md file in a PHP project?
- A) To store database credentials
 - B) To describe the project, its purpose, installation instructions, and usage
 - C) To execute PHP scripts
 - D) To list all dependencies
Answer: B) To describe the project, its purpose, installation instructions, and usage 
99.                     How should sensitive information such as API keys or database credentials be handled in a PHP project?
- A) Store them in the codebase
 - B) Store them in environment files and never expose them in version control
 - C) Keep them in the session
 - D) Hardcode them into the HTML output
Answer: B) Store them in environment files and never expose them in version control 
100.               Which of the following is a recommended practice for PHP project documentation?
- A) Writing minimal comments in the code
 - B) Providing clear instructions on setting up the project and troubleshooting
 - C) Using long-form explanations that are hard to understand
 - D) Avoid writing documentation
Answer: B) Providing clear instructions on setting up the project and troubleshooting 
