koduleht.eu
Teenused
Hinnastus
Meist
KKK
Kontakt
Tee päring
Teenused
Hinnastus
Meist
KKK
Kontakt
Tee päring
PHP TEST
Assess your PHP knowledge & skills
1. What does PHP stand for?
Personal Hypertext Preprocessor
Hypertext Preprocessor
Preprocessor for Home Pages
2. Explain the difference between 'echo' and 'print' in PHP.
'echo' outputs HTML code, 'print' outputs plain text.
'echo' outputs multiple values, 'print' returns 1.
'echo' is used for numbers, 'print' is used for strings.
3. How do you declare a variable in PHP?
variableName = value;
$variableName := value;
$variableName = value;
4. What's the difference between '==' and '===' in PHP for comparison?
'==' performs strict comparison, '===' performs type coercion.
'==' performs loose comparison, '===' performs strict comparison.
'==' compares values, '===' compares references.
5. How can you prevent SQL injection in PHP?
Use plain SQL queries with user inputs.
Use prepared statements with parameterized queries or an ORM library.
Sanitize user inputs with 'strip_tags()' before using them in queries.
6. Explain the usage of the ternary operator in PHP.
Ternary operator evaluates both true and false conditions.
Ternary operator is a shorthand for an if-else statement.
Ternary operator is used for arithmetic calculations.
7. What is a session in PHP?
A way to store data in files on the server.
A method to send cookies to clients
A way to store user-specific data across requests using cookies.
8. How can you start a session in PHP?
'session_begin()'
'start_session()'
'session_start()'
9. What's the difference between include and require in PHP for file inclusion?
Both 'include' and 'require' are used for conditional file inclusion.
'include' issues a warning if the file is not found, 'require' issues a fatal error.
'include' performs a deep copy of the included file.
10. Explain the concept of autoloading in PHP.
Autoloading automatically includes all available classes.
Autoloading loads classes on-demand without manual 'require'
Autoloading is a process of loading CSS files for styling.
11. What is the difference between public, protected, and private visibility in class properties in PHP?
'public' properties can be accessed within the class and its subclasses.
'protected' properties are accessible from anywhere.
'private' properties are only accessible within the class itself.
12. How can you prevent cross-site scripting (XSS) attacks in PHP?
Use 'eval()' to execute user input securely.
Sanitize output only when displaying user input.
Use 'htmlspecialchars()' when displaying user input and validate/sanitize input before usage.
13. Explain the concept of namespaces in PHP.
Namespaces provide encapsulation for a single class.
Namespaces are used for renaming functions and variables.
Namespaces help organize and avoid naming conflicts in code.
14. What is the difference between 'GET' and 'POST' methods in form submissions?
'GET' is used for secure data submissions, 'POST' is used for general requests.
'GET' appends data to the URL, 'POST' sends data in the HTTP request body.
'GET' is faster than 'POST' due to direct data transfer.
15. How do you handle file uploads in PHP?
Use the '$_FILE' superglobal for accessing uploaded files.
Use the '$_FILES' superglobal and validate the file type and size before saving it.
File uploads can be directly accessed in the script without superglobals.
16. Explain the concept of inheritance in object-oriented programming (OOP).
Inheritance allows a class to inherit methods from another class.
Inheritance restricts class extensions to one level.
Inheritance creates a parent-child relationship for sharing properties and methods.
17. What is the purpose of the 'final' keyword in PHP classes?
'final' restricts a class from being instantiated
'final' indicates a class can only have one instance.
'final' prevents a class from being extended or overridden by other classes.
18. How can you handle errors in PHP?
PHP handles errors automatically without any intervention.
Use the 'error()' function to handle errors globally.
Use 'try', 'catch' for exceptions and 'error_reporting' for error levels to handle errors effectively.
19. Explain the difference between 'PDO' and 'mysqli' for database access in PHP.
'PDO' is specific to MySQL databases, 'mysqli' is used for multiple database systems.
'mysqli' provides a consistent API, while 'PDO' is only for MySQL.
'PDO' is a consistent API for multiple databases, 'mysqli' is specific to MySQL.
20. How can you secure sensitive data like database credentials in a PHP application?
Store credentials in plain text files outside the web root.
Encrypt credentials using MD5 before storing.
Store credentials in environment variables or a configuration file outside the web root.
Submit