How do you handle errors when using output control functions in PHP?

  • Check the return values, use conditional statements, and utilize error handling techniques
  • Ignore errors, suppress error messages using the @ operator
  • Use the display_errors PHP configuration directive
  • All of the above
When using output control functions in PHP, you can handle errors by checking the return values of the functions. Many PHP functions return false or other specific values to indicate an error. By checking these return values, you can detect errors and take appropriate actions, such as displaying an error message, logging the error, or executing alternative code paths. Additionally, you can use conditional statements and error handling techniques like try-catch blocks to handle exceptions that may occur during function execution. It's important to handle errors effectively to ensure proper program execution and provide a good user experience.

You have a PHP script and you need to access a constant of a class. How would you do this?

  • ClassName::CONSTANT_NAME
  • $class->CONSTANT_NAME
  • self::CONSTANT_NAME
  • $this->CONSTANT_NAME
To access a constant of a class in PHP, you can use the class name followed by the scope resolution operator :: and the constant name. For example: ClassName::CONSTANT_NAME This allows you to directly reference the value of a constant defined within a class without the need for object instantiation. The self keyword can also be used to access the constant within the class itself. To learn more, visit: http://php.net/manual/en/language.oop5.constants.php

To connect to a MySQL database in PHP, you can use the mysqli_connect function like $conn = mysqli_connect(______, _______, _______, ______);.

  • host, username, password, database
  • server, user, pass, db
  • host, user, password, db
  • server, username, pass, database
To establish a connection to a MySQL database in PHP using the mysqli extension, you would use the mysqli_connect function. It takes four parameters: the host, username, password, and database name. These parameters are used to connect to the MySQL server and select the desired database. The function returns a connection object ($conn in this case) that can be used for further database operations. Ensure you provide the correct credentials and appropriate server details to establish a successful connection.

A common use case for the $_GET superglobal in PHP is to collect the data sent in the ______.

  • URL's query string
  • Request body
  • Path parameters
  • Headers
A common use case for the $_GET superglobal in PHP is to collect the data sent in the URL's query string. This includes parameters or values appended to the URL as key-value pairs. By using the $_GET superglobal, you can access and process this data to dynamically generate content, perform searches, or filter data based on user input. The other options, such as request body, path parameters, or headers, are not specifically associated with the $_GET superglobal. Learn more: https://www.php.net/manual/en/reserved.variables.get.php

You have a PHP script and you need to create an object from a class. How would you do this?

  • Using the new keyword and the class name
  • Using the create() function and the class name
  • Using the instanceof keyword and the class name
  • Using the object() function and the class name
In PHP, to create an object from a class, you use the new keyword followed by the class name and parentheses. The correct option is "Using the new keyword and the class name." This instantiates an object based on the defined class. For more information, consult the PHP documentation on creating objects: http://php.net/manual/en/language.oop5.php

How can you propagate a session id?

  • Using cookies
  • Using URL parameters
  • Using HTTP headers
  • All of the above
A session id can be propagated using cookies, URL parameters, or HTTP headers. These methods allow the server to identify the client's session. Learn more: http://php.net/manual/en/intro.session.php

PHP code is enclosed in ______ and ______ tags.

  • <?php, ?>
  • <html>, </html>
  • <php>, </php>
  • <script>, </script>
PHP code is typically enclosed in <?php and ?> tags. When the PHP interpreter encounters these tags, it knows to start and stop interpreting the code between them as PHP code. This allows you to embed PHP code in an HTML file. Learn more: https://www.php.net/manual/en/language.basic-syntax.phptags.php

Explain how you can update Memcached when you make changes to PHP?

  • Memcached does not require updating when making changes to PHP
  • Restart the Memcached server
  • Clear the Memcached cache
  • None of the above
To update Memcached when making changes to PHP, you need to clear the Memcached cache. This ensures that the updated data and changes are reflected in the cache. You can do this by flushing or deleting the relevant keys or by clearing the entire cache. Learn more: http://php.net/manual/en/book.memcached.php

What is the default keyword used for in a PHP switch statement?

  • To specify a block of code to be executed if no case matches the expression
  • To set a default value for the switch statement
  • To skip the current case and move to the next case
  • To end the switch statement and resume normal execution
In a PHP switch statement, the default keyword is used to specify a block of code to be executed if no case matches the expression. It serves as the default option when none of the case conditions evaluate to true. The default case is optional and is placed at the end of the switch statement. If no case matches the expression, the code block following the default case is executed. The default case allows you to define a fallback action or a default behavior when none of the specific cases are met. Learn more: https://www.php.net/manual/en/control-structures.switch.php

What can be potential issues when working with the $_POST superglobal in PHP?

  • Security vulnerabilities due to inadequate input validation and sanitization.
  • Data loss during transmission.
  • Limited data storage capacity.
  • Compatibility issues with certain web browsers.
When working with the $_POST superglobal, potential issues can arise due to security vulnerabilities. It is important to properly validate and sanitize the input received through $_POST to prevent attacks like SQL injection or cross-site scripting. Data loss during transmission or limited data storage capacity are not directly related to the $_POST superglobal. Compatibility issues with web browsers do not specifically apply to the $_POST superglobal, but rather to the general functionality of web applications. Learn more: https://www.php.net/manual/en/security.php