What are the main features of PHP?
PHP is a server-side scripting language designed for web development. It supports integration with multiple database types, has built-in functions for handling forms, and offers session management, error reporting, and more.
What is the latest version of PHP, and what are its new features?
As of October 2023, the latest stable version is PHP 8.1. It includes features like readonly properties, new enums, intersection types, and performance improvements.
Explain how session handling works in PHP.
Sessions in PHP allow data to persist across multiple web pages. PHP assigns a unique session ID to a user's session and stores session data on the server, which can be accessed via the `$_SESSION` superglobal array.
What is Composer in PHP?
Composer is a dependency manager for PHP, allowing developers to manage project libraries and dependencies efficiently. It enables easy installation, updating, and version management of PHP packages.
Explain the difference between GET and POST methods in PHP.
GET appends data to the URL and is used to retrieve information from the server. POST is used to send data securely via the HTTP message body, suitable for form submissions and handling sensitive data.
How do you connect PHP to a database?
PHP can be connected to a database using different extensions like MySQLi or PDO (PHP Data Objects). These provide methods for executing SQL queries, fetching data, and managing database connections.
What is an SQL injection? How can it be prevented in PHP?
SQL injection is a security vulnerability where an attacker can manipulate SQL queries. It can be prevented by using prepared statements and parameterized queries provided by PDO or MySQLi.
Explain error handling in PHP.
PHP has different levels of error handling such as notices, warnings, and fatal errors. Developers can use `try-catch` blocks, custom error handlers, and functions like `error_reporting()` to manage errors effectively.
What is PSR in PHP, and why is it important?
PSR (PHP Standards Recommendations) are coding guidelines developed by the PHP-FIG standards group to improve code interoperability and quality. Adopting these guidelines ensures a consistent and maintainable codebase.
How do namespaces work in PHP?
Namespaces in PHP prevent name collisions by encapsulating code. They allow the same name to be used for more than one class, function, or constant, as long as they are in different namespaces.