test 2 php
To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:
$days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days);
You can use the ______ variable within a class to refer to the current object that has been created from the class
$this
which of the following will match a tab in PHP regular expression?
/t
If a request is not sent, a session will end by default after ________________ have passed.
24 minutes
________________ provide a way for a web application to store information in the user's web browser and retrieve it every time the user requests a page.
Cookies
If the date is December 25, 2017, what output would be produced by the code below? echo date('M. d, Y');
Dec. 25, 2017
If the date is December 25, 2017, what output would be produced by the code below? echo date('F d, Y');
December 25, 2017
If you wanted to code a catch block that catches all types of exceptions and gets the message associated with the you start the catch block like this:
catch (Exception $e){
Which PHP function can be used to check if a specified class has been defined?
class_exists()
Which of the following is a nested function that has access to the outer function's local variables?
closure
A ________ is a special method within a class that is executed when a new object is created from the class
constructor
Which PHP function returns the number of elements in an array?
count()
The $_SESSION variable for a session
is an associative array
A ________________ is a special type of array that implements a first-in, first-out collection of values.
queue
Which term describes locations in the code that have access to a variable?
scope
Which PHP function can be used to end a session?
session_destroy()
Which PHP function is used to create a cookie?
setcookie()
Which date string matches the pattern that follows? /^[01]?\d\/\d{4}$/
"02/34/1968"
To get the value of a cookie, you can use the autoglobal ______________ variable.
$_COOKIE
Once a session is started, which superglobal variable can be used to get and set the user's data for a session?
$_SESSION
Which of the following statements is NOT a valid way to create a timestamp named $birthdate that represents December 2, 1969?
$birthdate = mktime(12, 2, 1969);
Suppose an associative array is added to a regular array by these statements: $cart = array(); $item = array(); $item['itemCode'] = 123; $item['itemName'] = "Visual Basic"; $item['itemCost'] = 57.5; $item['itemQuantity'] = 5; $cart[] = $item; To refer to the "itemCost" element in the associative array that's within the regular array, you would use this code:
$cart[$item['itemCost']]
To refer to a public property named categoryName for an object that's referenced by $category, you code
$category-> categoryName
What will the value of the $totals_string variable be after the following code is executed? $totals = array(141.95, 212.95, 411, 10.95); $totals[2] = 312.95; $totals_string = ""; for ($i = 0; $i < count($totals); $i++) { $totals_string .= $totals[$i] . "|"; }
141.95|312.95|411|10.95|
If a match is found in a global search for a regular expression, the function returns
A count of the number of matches and an array that contains all of the matches
If a match is found when the preg_split() function is executed, it returns
An array of the substrings that are created by removing the matches
What output would be produced by the code below? $names = array('Ron Burgundy', 'Brick Tamland', 'Champ Kind', 'Veronica Corningstone', 'Brian Fantana'); echo $names[1];
Brick Tamland
What is the default name of a session cookie in PHP?
PHPSESSID
_____properties and methods are inherited by a subclass but not accessible outside of the class
Private
To avoid the duplication of function names, you can
Use namespaces
You can deal with gaps in an array in all but one of the following ways. Which one is it?
Use the array_fill() function to replace all gaps in the array with empty strings.
Which of the following statements about associative arrays is NOT true?
You can use a foreach loop to access the values of an associative array but not the indexes
Which of the following will match any character that is NOT a letter number, or underscore in a PHP regular expression?
\W
Which character is used to signify the beginning or the end of a word in a PHP regular expression?
\b
which of the following will match any digit in a PHP regular expression?
\d
Which of the following will match any letter, number, or underscore in a PHP regular expression?
\w
Which character is used to signify the beginning of the string in a PHP regular expression?
^
$current_date = new DateTime(); $due_days_diff = $current_date->diff($due_date); if ($current_date > $due_date) { $overdue_message = $due_days_diff->format( '%y years, %m months, and %d days overdue.'); } (Refer to code example 10-1) If $due_date contains a DateTime object, $due_date_diff will contain
a DateInterval object
When you use session tracking, each HTTP request includes
a cookie that stores the session ID
The function that follows returns function coin_toss() { if (mt_rand(0, 1) == 0) { $coin = 'heads'; } else { $coin = 'tails'; } return $coin; }
a value of either "heads" or "tails"
In PHP, function name duplications are likely to occur because
all functions have global scope
Which of the following is a parameter of the setcookie() function?
all of these
Which of the following is considered a scalar value?
all of these
Which type of PHP function does not have a name?
anonymous
When you call a function, you can pass ________________ as values that correspond with the parameters of the function.
argument
Which of the following functions would you use to define a constant that stores an array in PHP 7.0 or later?
array_constant()
Which of the following functions removes the next element in a LIFO array (also known as a stack)?
array_shift()
Which PHP function returns an array with the elements of two or more arrays in one array?
array_splice()
Which of the following is a PHP function that returns the sum of the elements in an array?
array_sum()
An array that uses strings as indexes in PHP is known as a/an ________________ array.
associative
Which of the following is a function that is passed as an argument to another function?
callback
regular expression
can be used to completely validate all types of user entries
If you create a function that passes an argument by reference, the function
can change the variable and pass it back by using a return statement
To call a static method named randomized in class named Cart you code
cart:: randomize()
Which method of a DateTime object can be used to determine an amount of time between two dates or times?
diff()
Runtime errors that occur due to unexpected error conditions are called?
exceptions
A subclass can ____ the superclass by adding new properties and methods
extend
Suppose an array of country codes and country names is created with a statement like this: $country_codes = array('DEU' => 'Germany', 'JPN' => 'Japan', 'ARG' => 'Argentina', 'USA' => 'United States'); If you want to use echo statements to display a table of all of the codes and names, you could code those statements within a loop that starts like this:
foreach ($country_codes as $code => $name) {
All of the arguments that are passed to a function are available in an array that can be accessed by using the
func_get_args function
To create a function named randomize that has one parameter that has a default value of 5 and one required parameter that's passed by reference, you start the function like this:
function randomize($&parm1, $parm2 = 5) {
To get the message that's related to an exception, you can use the
getMessage() method of the exception object
What modifier can be added to the end of a regular expression in PHP to make it case insensitive?
i
To create an object from a class named Cart that requires two argument, you COde
new Cart($arg1, $arg2)
What output would be produced by the code that follows? $names = array('Ron Burgundy', 'Brick Tamland', 'Champ Kind', 'Veronica Corningstone', 'Brian Fantana'); echo $names[5];
none of these
When you use object-oriented techniques the MVC pattern, the methods of the model return the data as either arrays or
objects
When a new class extends a superclass, it inherits the properties and methods of the superclass. Then, it can
override the inherited methods
When creating functions, you can include ______________ that are located inside parentheses after the function name.
parameters
A cookie that does not expire when the user closes his or her browser is a(n) ________________ cookie.
persistent
A ________________ is a special type of array that implements a last-in, first-out collection of values.
pop
which function searches for a regular expression in a string and returns 1 if the pattern is found?
preg_match()
To code a method within a class the sets the value for a private property named $name based on the argument that's passed to it, you start with this code
private function setName($value){
Which of the following are variables that store the data for a class?
properties
By default the properties of a PHP class are
public
To code a constructor for a class name Cart that requires two arguments, you start with this code
public function_construct($arg1, $arg2){
To prevent other classes from directly accessing the properties of a class, you can code them as private. Then, to make them available to other classes, you can code
public methods to set and get their values
which of the following are coded patterns that you can use to search for matching patterns in text strings?
regular expressions
Which PHP function is used to start a new session or resume a previous session?
session_start()
To delete a cookie, you
set the cookie's value to an empty string and its expiration date to a time in the past
Which of the following is a PHP function that shuffles the values in an array in a random order?
shuffle()
Which of the following is a PHP function for sorting arrays?
sort()
A list of functions or methods in the reverse order in which they were called is an
stack trace
Gaps can be introduced into an array in all of the ways that follow, exept one. Which one is it?
store a NULL value in an array
The easiest way to add the values in an array is to use
the array_sum() function
If you want to create an exception within a data-validation function and throw it to the statement that called the function, you code
throw new Exception("Validation error");
A ______________ is an integer that represents a date and time as the number of seconds since midnight, January 1, 1970.
timestamp
When you create a DateInterval object, you pass it one argument that specifies one or more of the following:
years, months, days, hours, minutes, seconds
Timestamps will encounter a(n) _______ problem if they are not converted to DateTime objects.
Y2K38
Which of the following statements about an array of arrays is true?
You can use both for loops and foreach loops to work with an array of arrays.
You can use PHP 7 and later to catch and handle
all fatal errors that are recoverable
Which of the following is a PHP function that is used to count the number of times each value in an array is used?
array_count_values()
Which character is used to signify the end of the string in a PHP regular expression?
$
If the date is December 25, 2017, what output would be produced by the code below? echo date('n/d/Y h:i A')
12/25/2017 12:00 AM
Given the code that follows, $employees = array(); $employee["name"] = "John Smith"; $employee["age"] = 29; which of these statements assigns "John Smith is 29" to $message?
$message = $employee["name"] . " is " . $employee["age"];
Which parameter of the session_set_cookie_params() function can be set so the cookie is only available on an HTTPS connection?
$secure
Which pattern can be used to validate a five_digit zip code:?
/^\d{5}$/
Which of the following will match a new line in a PHP regular expression?
/n
Which of the following will match a carriage return in PHP regular expression?
/r
$current_date = new DateTime(); $due_days_diff = $current_date->diff($due_date); if ($current_date > $due_date) { $overdue_message = $due_days_diff->format( '%y years, %m months, and %d days overdue.'); } (Refer to code example 10-1) If $due_date contains a DateTime object for a date that comes 1 month and 7 days before the date stored in the $current_date variable, what will $overdue_message contain when this code finishes executing:
0 years, 1 months, and 7 days overdue.
If the date is December 25, 2017, what output would be produced by the code below? echo date('n/j/Y');
12/25/17
If the date is December 25, 2017, what output would be produced by the code below? echo date('n/j/y');
12/25/2017
