PHP - Skill Assignment Quiz

Q1. What does this code output?

  • 1
  • -1
  • a parser error
  • 0

Q2. Which is the most secure way to avoid storing a password in clear text in database?

  • $encrypted = shal($password);
  • $encrypted = crypt($password, \$salt);
  • $encrypted = md5($password);
  • $encrypted = password_hash($password, PASSWORD_DEFAULT);

Q3. In a conditional statement, you want to execute the code only if both value are true. Which comparison operator should you use?

  • ||
  • &
  • <=>
  • &&

Q4. All variables in PHP start with which symbol?

  • &
  • %
  • _
  • $

Q4. All variables in PHP start with which symbol?

  • &
  • %
  • _
  • $

Q5. What is a key difference between GET and POST?

  • GET is used with the HTTP protocol. POST is used with HTTPS.
  • GET displays the submitted data as part of the URL. During POST, this information is not shown, as it's encoded in the request body.
  • GET is intended for changing the server state and it carries more data than POST.
  • GET is more secure than POST and should be used for sensitive information.

Q6. The ** operator is useful for sorting operations. It compares two values and returns an integer less than, equal to, or greater than 0 depending on whether the value on the ** is less than, equal to, or greater than the other.

  • greater-than; right
  • spaceship; left
  • equality; right
  • comparison; left

Q7. Which are valid PHP error handling keywords? try, throw, catch, callable try, yield, catch, finally yield, throw, catch, finally try, throw, catch, finally

  • try, throw, catch, callable
  • try, yield, catch, finally
  • yield, throw, catch, finally
  • try, throw, catch, finally


Q8. Which value equates to true?

  • 0
  • NULL
  • ''
  • -1


Q8. Which value equates to true?

  • 0
  • NULL
  • ''
  • -1

Q9. What is the purpose of adding a lowercase "u" as a modifier after the final delimiter in a Perl-compatible regular expression?

  • It makes the dot metacharacter match anything, including newline characters.
  • It makes the pattern match uppercase letters.
  • Both the pattern and subject string are treated as UTF-8.
  • It inverts the greediness of the quantifiers in the pattern so they are not greedy by default.

Q10. Which code snippet uses the correct syntax for creating an instance of the Pet class?

  • $dog = new Pet;
  • all of these answers
  • $horse = (new Pet);
  • $cat = new Pet();

Q11. Which is the correct format for adding a comment to a PHP script?

  • all of these answers
  • #This is a comment
  • /* This is a comment */
  • // This is a comment

Q12. PHP supports multiple types of loops. If you wanted to loop through a block of code if and as long a specified condition is true, which type of loop would you use?

  • for
  • do-while
  • while
  • foreach

Q13. The ignore_user_abort( ) function sets whether a client disconnect should abort a script execution. In what scenario would you, as a web developer, use this function?

  • You would use it to stop a user from clicking the back button if they decide not to view as a result of a click.
  • You would use this function if you have some important processing to do and you do not want to stop it, even if your users click Cancel.
  • You would use this function if you wanted to abort the script for all logged-in users, not just the one who disconnected.
  • You would use this function if you want a PHP script to run forever.

Q14. How might you troubleshoot a "call to undefined function" error?

  • Make sure you have imported the file containing the function.
  • Make sure you have spelled the function name correctly.
  • all of these answers
  • Make sure the function declaration is at an earlier point in the code than the function call.

Q15. Which line could you NOT use to comment out "Space: the final frontier"?

  • /* Space: the final frontier */
  • */ Space: the final frontier /*
  • #Space: the final frontier
  • // Space: the final frontier

Q16. What displays in a browser when the following code is written?

  • The browser would display nothing due to a syntax error.
  • The browser would display an error, since there are no parentheses around the string.
  • The browser would display How much are the bananas?
  • The browser would display an error, since there is no semicolon at the end of the echo command.

Q17. Assuming the Horse class exists, which is a valid example of inheritance in PHP?

  • class Pegasus extends Horse {}
  • class Alicorn imports Pegasus, Unicorn {}
  • class Unicorn implements Horse {}
  • class Horse inherits Unicorn {}

Q18. Both triple === and double == can be used to ** variables in php. If you want to hear that string "33" and the number 33 are equal, you would use ** . If you want to check if an array contains a particular string value at a particular index, you would use _

  • compare; doubles; triples
  • compare; triples; doubles
  • assign; triples; doubles
  • assign; doubles; triples

Q19. Your php page is unexpectedly rendering as totally blank. Which step will shed light on the problem?

  • Add this code to the top of your script: ini_set('display_errors',1);
  • check the server error logged
  • all of these answers
  • make sure you are not missing any semicolons

Q20. Which code would you use to print all the elements in an array called $cupcakes?

  • all of the answers
  • print_r($cupcakes);
  • var_dump($cupcakes);
  • foreach($cupcakes as &$cupcake) echo $cupcake;

Q21. Which php control structure is used inside a loop to skip the rest of the current loops code and go back to the start of the loop for the next iteration

  • else
  • break
  • return
  • continue

Q22. The php not operator is !. Given the snippet, is there an out put and what is it?

  • there is an output '2 is an even number
  • output '21 is an odd number'
  • no output. Syntax error do to missing semicolon at the end
  • no output due to % in $num%2!=0

Q23. What is the job of the controller as a component in MVC?

  • The controller handles data passed to it by the view, and also passes data to the view. It interprets data sent by the view and disperses that data to the approrpiate models awaiting results to pass back to the view.
  • The controller is a mechanism that allows you to create reusable code in languages such as PHP, where multiple inheritance is not supported.
  • The controller presents content through the user interface, after communicating directly with the database.
  • The controller handles specific tasks related to a specific area of functionality, handles business logic related to the results, and communicates directly with the database.

Q24. A PDO object called $db has been set up to use for database operations, including user authentication. All user-related properties are set. The script line public function __construct(&$db) shows a constructor that initializes all user-related properties to _ if no user has logged in. These parameters will be properly set by the login functions when a user logs in.

  • NULL
  • TRUE
  • 0

Q25. What are getters and setters?

  • Getters and setters ensure that if a data member is declared private, then it can be accessed only within the same function, not by an outside class
  • Getters and setters are utility functions within PHP that allow loading from, and saving to, a database
  • Getters and setters encapsulate the fields of a class by making them acccessible only through its private methods, and keep the values themselves public
  • Getters and setters are methods used to declare or obtain the values of variables, usually private ones

Q26. What are some of the main types of errors in PHP?

  • notices, warnings, fatal
  • runtime, logical, compile
  • semantic, logical, syntax
  • warnings, syntax, compile

Q27. Assume that $r is 255, and $g and $b are both 0. What is the correct code to output "#ff0000"?

  • printf('#%2x%2x%2x', 255, 0, 0);
  • printf('#%2X%2X%2X', $r, 0, 0);
  • printf('#%x%x%x', 255, 0, 0);
  • printf('#%02x%02x%02x', 255, 0, 0);


Are you ready

Let’s Make Something Amazing Together

Need help? Contact our experts
Tell us about your project