CIST 2351 PHP Final Chapter 9-15
A switch statement in PHP starts by evaluating a switch _____ . A. case B. expression C. return statement D. break
B. expression
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 is the default name of a session cookie in PHP?
PHPSESSID
______________ properties and methods are inherited by a sublass but not accessible outside of the class
Protected
How many name=value pairs are in the following URL? <a href="http://www.URL.com/TargetPage.php?firstName=Bill&lastName=Sciuto&occupation=teacher ">Link Text</a>
Three
T/F: A DateInterval object represents an internval of time rather than a point in time.
True
T/F: Once a session is started, use the $_SESSION autoglobal to get and set the user's data for a session?
True
T/F: When you call a function, you can pass arguments as values that correspond with the parameters of the function.
True
T/F: You can use both for loops and foreach loops to work with an array of arrays.
True
A/an ________________ statement can be used to jump out of a loop.
break
A switch statement in PHP is often useful in the ________________ of an application that uses the MVC pattern.
controller
By default, PHP implements session tracking by using a/an __________ to store a session ID in the user's browser.
cookie
Persistent ____________________ remain available beyond the current browser session
cookies
A foreach loop can be used to get both the ________________ and the value for each element in an associative array.
key
When you use inheritance to create a new class from an existing class, the new class starts with the public properties and ________________ of the existing class.
methods
A method is a/an ________________ that's coded within a class.
function
If you create a function with a variable number of parameters, you need to use a PHP ________________ to get an array of the arguments that are passed to the function.
function
To get the message that's related to an exception, you use the ________________ method of the exception object.
getMessage
By using the ________________ function, you can send special characters to the browser in a way that they will be displayed correctly.
htmlentities
In many programming languages, cookies cannot include special characters because they are transmitted between Web browsers and servers using ____________________.
http
To create a case-insensitive regular expression, you code the letter ________________ at the end of the expression.
i
The ____ function returns a Boolean value of true if a given value exists in the array.
in_array()
You create a cookie by passing to the setcookie() function a required ____ argument and five optional arguments.
name
If you use the unset function to delete the value of an element in an array, the value is replaced by a/an ________________ value, thus creating a gap in the array.
null
____________________ databases consist of one or more related tables.
relational
When you use the strtotime function, you can use an absolute template to create a timestamp for the date that you specify, or you can use a ________________ template to create a timestamp for the current date and adjust it based on the offsets that you specify.
relative
The ________________ operator has the highest order of precedence of the logical operators.
!
You can access the values submitted from the form by using the $_GET[] and ____ autoglobals.
$_POST[]
A session ID lets PHP associate a user with the data that's stored in the related __________ array.
$_SESSION
Because most systems today store timestamps as 32-bit signed integers, the upper limit of a timestamp on these systems is January 19 in the year________________.
2038
To assign the first element of an associative array with a number other than zero (0), use the array operator ____________________ .
=>
The ________________ operator returns a TRUE value if the expression on its left is greater than or equal to the expression on its right.
>=
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 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?
^
If you want to code a catch block that catches all types of exceptions and gets the message associated with the exception, you start the catch block like this.
catch (Exception $e) {
A/an ________________ defines the methods and properties of an object.
class
To create an exception, you code the new keyword followed by the name of the ________________ that defines the exception followed by a set of parentheses that contains the message for the exception.
class
To get the value of a cookie, you can use the autoglobal ______________ variable. A. $_COOKIE B. $_SESSION C. $_GET D. $_EAT
A. $_COOKIE
When you use a for loop to process the values in a regular array, the counter value can be used to refer to each ________________ in the array.
element
To refer to a public property named categoryName for an object that's referenced by $category, you code A. $category->categoryName B. $category->$categoryName C. $category::categoryName D. $category::$categoryName
A. $category->categoryName
To avoid the duplication of function names, you can A. Use namespaces B. Use libraries C. Store function files in lower-level directories D. Use include paths
A. Use namespaces
Which of the following is a PHP function that is used to count the number of times each value in an array is used? A. array_count_values() B. isset() C. num_elements() D. count_values()
A. array_count_values()
A/an ________________ loop tests its conditional expression at the end of the loop.
do-while
The ____ argument is used for sharing cookies across multiple servers in the same domain.
domain
To create a default value for a parameter in the parameter list of a function, you code a/an ________________ sign after the parameter name followed by the default value.
equals
The symbol (@), used to suppress error messages, is called ____.
error control operator
By using ________________ sequences, you can put special characters into a string literal that would otherwise be interpreted incorrectly by PHP.
escape
Which of the following is a PHP function that returns the sum of the elements in an array? A. array_sum() B. add_elements() C. array_product() D. elements_sum(
A. array_sum()
Which of the following is a function that is passed as an argument to another function? A. callback B. anonymous C. restricted D. value
A. callback
If you create a function that passes an argument by reference, the function A. can change the original variable without using a return statement B. can change the variable and pass it back by using a return statement C. can't change the variable D. must make a copy of the variable before it changes it
A. can change the original variable without using a return statement
Which of the following is a nested function that has access to the outer function's local variables? A. closure B. global C. stacked D. illegal
A. closure
Which of the following is a special method executed when a new object is created from a class? A. constructor B. destructor C. inheritor D. encapsulator
A. constructor
Which method of a DateTime object can be used to determine an amount of time between two dates or times? A. diff() B. datediff() C. datebetween() D. add()
A. diff()
A fundamental concept of object-oriented programming that groups related data and functionality in a class is called ____________________. A. encapsulation B. portability C. inheritance D. normalization
A. encapsulation
Which PHP function returns a string with all special HTML converted to the HTML entity? A. htmlentities() B. encode_entity() C. converthtml() D. htmlencode()
A. htmlentities()
Which PHP function can be used to determine if an object is an instance of a class? A. is_a() B. class_exists() C. get_class() D. check_instance()
A. is_a()
A variable declared inside a PHP function would be considered a ____________ variable. A. local B. global C. moduler D. block-level
A. local
To create an object from a class named Cart that requires two arguments, you code A. new Cart($arg1, $arg2) B. new Cart(arg1, arg2) C. Cart_constructor($arg1, $arg2) D. Cart_constructor(arg1, arg2)
A. new Cart($arg1, $arg2)
When creating functions, you can include ______________ that are located inside parentheses after the function name. A. parameters B. returns C. brackets D. comments
A. parameters
A timestamp stores the number of _____ since midnight on January 1, 1970 GMT. A. seconds B. minutes C. hours D. days
A. seconds
Which PHP function is used to create a cookie? A. setcookie() B. $_COOKIE() C. create_cookie() D. make_cookie()
A. setcookie()
A _____ is an integer that represents a date and time as the number of seconds since midnight, January 1, 1970. A. timestamp B. intdate C. date_format D.checkdate
A. timestamp
By default, all arguments passed to PHP functions are passed by ________________. A. value B. reference C. sequence D. read access
A. value
An if statement can be used to implement a _____ structure. A.selection B.sequence C. case D. mysql_error()logical
A.selection
The array_push() function ____ one or more elements to the end of the array.
Adds
Runtime errors that occur due to unexpected error conditions are called ________________.
exceptions
If the regular expression that's specified by the preg_match function contains errors, the function returns ________________.
false
A function library is just a/an ________________ that contains one or more functions.
file
A/an ________________ loop is typically used when the loop requires a counter variable.
for
Once a session is started, which autoglobal can be used to get and set the user's data for a session A. $_COOKIE B. $_SESSION C. $_GET D. $_USER
B. $_SESSION
The date function makes it easy to create a timestamp for the current date and ________________ it before returning the value.
format
You can use the sprintf function to precisely format strings and numbers by specifying the required ________________ in the first argument that you pass to it.
format codes
To make a cookie available to all directories, use a(n) ____________________ to indicate the root directory.
forward slash
Within a function, you can use the ________________ keyword if you need to refer to a variable that's declared outside the function.
global
To create a persistent cookie, set one of the __________ of the setcookie function.
parameters
The ____________________ argument determines the availability of a cookie to other Web pages on the server
path
A regular expression defines a/an ________________ that can be searched for in a string.
pattern
A substring within a string is identified by its length and its starting ________________ within the string.
position
Which function searches for a regular expression in a string and returns 1 if the pattern is found?
preg_match
A(n) ____________________ string consists of a single text string containing one or more pieces of information.
query
One way to preserve information following a user's visit to a Web page is to append a ____ at the end of a URL.
query string
To pass information from one page to another using a query string, you add a(n) ____ immediately after the URL, followed by the query string containing the information you want to preserve in name=value pairs.
question mark
A/an ________________ is a type of array in which the first element added is the first to be removed.
queue
When you use session tracking, each HTTP request includes a cookie that stores the __________ ID.
session
A(n) ____________________ is a random alphanumeric string generated by the session_start() function.
session ID
A session starts when a browser makes its first request to a page that executes the __________ function.
session_start
After you create a DateTime object, you can use its setTime method to change the time or its ________________ method to change the date.
setDate
Which PHP function is used to create a cookie?
setcookie
The ____________________ function converts special characters in a text string to their corresponding hexadecimal ASCII value.
setcookie()
The most commonly used array sorting functions are ____________________ and rsort() for indexed arrays.
sort()
A ________________ is a special type of array that implements a last-in, first-out collection of values?
stack
A list of functions or methods in the reverse order in which they were called is a(n)________________.
stack trace
If a Web site stores no persistent data about a visit to a Web site, it is said to be ____________________.
stateless
A ________________ property or method is one that belongs to a class, not to an object.
static
To refer to an element in an associative array, you use a/an ________________ as the index.
string
To remove multiple elements using the unset() function, separate each ____ name with commas
Element
T/F: By default, the properties of a PHP class are protected.
False
T/F: You can use a foreach loop to access the values of an associative array but not the indexes.
False
If a number in a PHP application is larger than the maximum value that PHP provides for, it is converted into the PHP constant named ________________.
INF
Multidimensional arrays are not limited to ____.
two dimensions
Which combination of operators does NOT perform type coercion?
===
Which parameter of the session_set_cookie_params can be set so the cookie is only available on an HTTPS connection?
$secure
You can use the ________________ variable within a class to refer to the current object that has been created from the class.
$this
Which character is used before an argument to specify that the variable is being passed to a PHP function by reference?
&
The ________________ operator is a logical operator that returns a TRUE value when the expressions on both sides of the operator are TRUE.
&&
To call one of the methods for an object, you code the object name followed by ________________ and the method name.
-> (object access modifier)
This pattern can be used to validate a five-digit zip code.
/^\d{5}$/
What expression will match a carriage return in a PHP regular expression?
/r
What expression will match a tab in a PHP regular expression?
/t
The index value of the first element in a regular PHP array is ________________.
0
If a regular expression is found in the string that's specified by the preg_match function, the function returns ________________.
1
Web browsers can limit the total number of cookies stored on a user's computer to at least ____.
300
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
Which of the following statements is NOT a valid way to create a timestamp named $birthdate that represents December 2, 1969? A. $birthdate = mktime(0, 0, 0, 12, 2, 1969); B. $birthdate = mktime(12, 2, 1969); C. $birthdate = strtotime('1969-12-02'); D. $birthdate = strtotime('12/02/1969');
B. $birthdate = mktime(12, 2, 1969);
If the date is December 25, 2017, what output would be produced by the code below? echo date('n/d/y h:i A'); A. 12/25/1017 B. 12/25/2017 12:00 AM C. December 25, 2017 D. 12/25/17
B. 12/25/2017 12:00 AM
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] . "|"; } A. 141.95 | 312.95 | 411 | 10.95 B. 141.95 | 212.95 | 312.95 | 10.95 | C. 141.95 | 212.95 | 411 | 312.95| D. 10.95 |
B. 141.95 | 212.95 | 312.95 | 10.95 |
What output would be produced by the code below? $names = array('Ron Burgundy', 'Brick Tamland', 'Champ Kind', 'Veronica Corningstone', 'Brian Fantana'); echo $names[1]; A. Ron Burgundy B. Brick Tamland C. Champ Kind D. Veronica Corningstone
B. Brick Tamland
________________ 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. A. Bookmarks B. Cookies C. Favorites D. Status bars
B. Cookies
If the date is December 25, 2017, what output would be produced by the code below? echo date('M. d, Y'); A. 12/25/2017 B. Dec. 25, 2017 C. December 25, 2017 D. 12/25/17
B. Dec. 25, 2017
What does $message contain after the following code executes? $message = "L: "; for ($i = 0: $i < 10; $i++) $message .= $i . ", "; if (i == 7) break; A. L: 0, 1, 2 ,3 ,4 ,5, 6 ,7 ,8, 9, B. L: 0, 1, 2 ,3 ,4 ,5, 6, 7, C. L: 1, 3, 5, 7, 9, D. L: 1, 3, 5, 7
B. L: 0, 1, 2 ,3 ,4 ,5, 6, 7,
Timestamps will encounter a(n) _____ problem if they are not converted to DateTime objects. A. Y2K B. Y2K38 C. Y10K D. Y69K
B. Y2K38
When you use session tracking, each HTTP request includes A. a URL that stores the session ID B. a cookie that stores the session ID C. a cookie that stores the session data D. a cookie that stores the session ID and the session data
B. a cookie that stores the session ID
Which of the following statements will restart the execution of a loop? A. halt B. continue C. stop D. break
B. continue
A subclass can ____________ the superclass by adding new properties and methods. A. destruct B. extend C. clone D. create
B. extend
Suppose an array of country codes and country names is created with a statement like this: $country_codes = array('DEU => 'Germeny', '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: A. foreach ($country_codes as $name[code]) { B. foreach ($country_codes as $code => $name) { C. for ($country_codes as $name[code]) { D. for ($country_codes as $code => $name) {
B. foreach ($country_codes as $code => $name) {
Variable substitution is carried out by what process that converts a variable's value to a string? A. decimation B. interpolation C. coercion D. encapsulation
B. interpolation
The $_SESSION variable for a session A. is a regular array B. is an associative array C. is an object D. is a cookie
B. is an associative array
When a new class extends a superclass, it inherits the properties and methods of the superclass. Then, it can A. override the inherited properties B. override the inherited methods C. delete any of the inheritied properties D. delete any of the inherited methods
B. override the inherited methods
Which of the following are variables that store the data for a class? A. methods B. properties C. destructors D. brackets
B. properties
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 A. private methods to set and get their values B. public methods to set and get their values C. a constructor to set and get their values D. a destructor to set and get their values
B. public methods to set and get their values
If you want to round a number within an arithmetic expression, which function should you use? A. number_format() B. round() C. sprintf() D. math_round()
B. round()
Which PHP function can be used to end a session? A. session_start() B. session_destroy() C. session_stop() D. session_remain()
B. session_destroy()
Which of the following is a PHP function that shuffles the values in an array in a random order? A. reverse_sort() B. shuffle() C. rand_sort() D. array_rand()
B. shuffle()
Which PHP function returns the number of characters in the string? A. len() B. strlen() C. countchars() D. substr()
B. strlen()
When you use the substr() function to extract a substring, you need to at least pass an argument that gives A. the characters in the substring that you're looking for B. the starting position of the substring C. the length of the substring D. the separators for the substring
B. the starting position of the substring
What does $message contain after the following code executes? $statusCode = "403"; switch ($statusCode) { case "200": $message = "OK"; break: case "403": $message = "Forbidden"; break: case "404": $message = "Not Found"; break: default: $message = "Unknown Status"; break: A.OK B.Forbidden C. Not Found D. Unknown Status
B.Forbidden
Which type of statement ends the current iteration of a loop? A.break B.continue C.switch D. conditional
B.continue
Which type of loop will always execute its code at least once? A.while B.do-while C. for D. for-in
B.do-while
The use of ________________ objects resolves the Y2K38 problem because the upper limits of dates and times are essentially removed.
DateTime
Which of the following is NOT an escape sequence used in double-quoted strings in PHP? A. /n B. /t C. /c D. /r
C. /c
If a request is not sent, a session will end by default after ________________ have passed. A. 2 hours B. 5 minutes C. 24 minutes D. 30 seconds
C. 24 minutes
How many operands does a ternary operator have? A. 1 B. 4 C. 3 D. 2
C. 3
If the date is December 25, 2017, what output would be provided by the code below? echo date('F d, Y'); A. 12/25/2017 B. Dec. 25, 2017 C. December 25, 2017 D. 12/25/17
C. December 25, 2017
Which of the following statements about associative arrays is NOT true? A.You can use the count function to return the number of elements in the array B. You can use both integer and string indexes with an associative array C. You can use a foreach loop to access the values of an associative array but not the indexes D. You can delete elements from an associative array
C. You can use a foreach loop to access the values of an associative array but not the indexes
Which method of passing a variable allows the function to change the value of the variable? A. by scope B. by value C. by reference D. by name
C. by reference
Which PHP function can be used to check if a specified class has been defined? A. get_class() B. is_a() C. class_exists() D. property_exists()
C. class_exists()
All of the arguments that are passed to a function are available in an array that can be accessed by using the A. $_ARGUMENTS variable B. $_FUNCTION variable C. func_get_args function D. func_num_args function
C. func_get_args function
While loops and for loops are often referred to as _____ structures. A. selection B.sequence C. iteration D. ill-advised
C. iteration
A "natural" comparison of two values A. is case sensitive B. is case insensitive C. puts both "09" and "9" before "10" D. puts "10" before both "09" and "9"
C. puts both "09" and "9" before "10"
Which term describes locations in the code that have access to a variable? A. lifetime B. category C. scope D. data type
C. scope
The easiest way to add the values in an array is to use A. a for loop B. a foreach loop C. the array_sum() function D. the sum_array() function
C. the array_sum() function
CHAPTER 13
CHAPTER 13
To call a static method named randomize in a class named Cart, you code _______________.
Cart::randomize()
Chapter 10
Chapter 10
Chapter 11
Chapter 11
Chapter 12
Chapter 12
Chapter 13
Chapter 13
Chapter 14
Chapter 14
Chapter 15
Chapter 15
Chapter 8
Chapter 8
Chapter 9
Chapter 9
If you want to generate a random number that ranges from 1000 to 500,000 as a multiple of 100(1000, 1100, 1200, etc,), and store it in a variable named $number, you can use the code that follows. A. $number = mt_rand(1000,500000); B. $number = mt_rand(100,50000); $number *= 10; C. $number = mt_rand(1,500); $number *= 1000; D. $number = mt_rand(10,5000); $number *= 100;
D. $number = mt_rand(10,5000); $number *= 100;
If the date is December 25, 2017, what output would be produced by the following code? echo date('n/j/y'); A. 12/25/2017 B. Dec. 25, 2017 C. December 25, 2017 D. 12/25/17
D. 12/25/17
You can deal with gaps in an array in all but one of the following ways. Which one is it? A. Use the array_values function to remove all gaps and re-index the array B. Use a foreach loop to process the array, which skips elements that contain nulls C. Use a for loop that contains extra code that skips elements that contain nulls D. Use the array_fill function to replace all gaps in the array with empty strings
D. Use the array_fill function to replace all gaps in the array with empty strings
Which of the following can be used in a conditional expression? A.equality operators B. relational operators C. logical operators D. all of these
D. all of these
Which of the following is a PHP function for sorting arrays? A. sort() B. rsort() C. krsort() D. all of these
D. all of these
Which of the following is a parameter of the setcookie function? A. $name B. $value C. $expire D. all of these
D. all of these
Which of the following is a way to assign a string to a variable on PHP? A. single quotes B. double quotes C. heredoc D. all of these
D. all of these
To delete a cookie, you A. delete the $_COOKIE variable B. use the delete_cookie function C. use the remove_cookie function D. set the cookie's value to an empty string and its expiration date to a time in the past
D. set the cookie's value to an empty string and its expiration date to a time in the past
When you create a DateInterval object, you pass it one argument that specifies one or more of the following: A.years, months, days B. hours, minutes, seconds C. years, months, days, hours, minutes, seconds D.years, months, weeks, days, hours, minutes, seconds
D.years, months, weeks, days, hours, minutes, seconds
One of the methods of a DateTime object lets you add a/an __________ object to it.
DateInterval
Which of the following is not a tool for maintaining state information with PHP?
Functions
________________ provides a way to create a new class based on an existing class.
Inheritance
The array_unshift() function adds ____ element(s) to the beginning of the array.
One or more
The list of records that is returned from a mysql_query() is a called a ____.
Resultset
A result pointer is a special type of ____ that refers to the currently selected row in a resultset.
Variable
You separate individual name=value pairs within a query string using ____.
ampersands(&)
Which type of PHP function does not have a name?
anonymous
To call a function, you code the function name followed by a set of parentheses that contains a list of the required ________________.
arguments
You use the ____________________ function to create a new associative array that uses the values from one array as keys and the values from another array as element values
array_combine()
You would use the ____________________ function t return an array of the elements that are common to all arrays that are compared.
array_intersect()
Which PHP function returns an array with the elements of two or more arrays in one array?
array_merge
Instead of appending one array to another, you can merge two or more arrays with the ____________________ function.
array_merge()
Merge two or more arrays with the ____ function.
array_merge()
Which function removes the next element in a LIFO array (also known as a stack)?
array_pop
The ____________________ function determines whether a given value exists in an array and returns the index or key of the first matching element if it exists or FALSE if it does not.
array_search
As with the array_values() function the ____________________ function does not operate directly on an array.
array_unique()
The ____ function removes duplicate elements from an array.
array_unique()
An array that uses strings as indexes in PHP is known as a(n) ________________ array.
associative
A cookie is a name/value pair that's stored in a/an __________.
browser
When you use object-oriented techniques to implement the MVC pattern, the model consists of ________________ that contain the required methods.
classes
Equality, relational, and logical operators can be used in a ________________ expression.
conditional
Which PHP function returns the number of elements in an array?
count
Type casting refers to PHP code that converts a value from one ________________ to another.
data type
The explode function returns an array of strings from a single string based on the ________________ character that you specify.
delimiter
The equality operators convert data from one type to another before performing a comparison, but the ________________ operators do not convert data before performing a comparison.
identity
You pass the unset() function the array name and the ____________________ of the element you want to remove.
index
The strcasecmp function is case-________________. As a result, "Anders" comes before "zylka".
insensitive
Which of the following is a term that describes the process of creating an object from a class?
instantiation
You can use the ____________________ function to ensure that a cookie is set before you attempt to use it.
isset()
To perform a reverse sort on an associative array by key and maintain the existing keys, use the _____ function.
krsort()
The ________________ of a string specifies the number of characters that it contains.
length
other questions:
other questions:
The ________________ function returns the largest value of the two or more arguments that are passed to it.
max
What is the PHP function used to get random numbers?
mt_rand
To create a DateTime object for the current date, you use the ________________ keyword and pass no arguments to the constructor.
new
To create an object from a class, you code the ________________ keyword followed by the class name and an argument list.
new
When you use object-oriented techniques to implement the MVC pattern, the methods of the model return the data as either arrays or _____________.
objects
The preg_replace function is used to replace the substring that is matched by a/an ________________ with a new substring.
regular expression
<, <=, and > are what kind of operators?
relational
You pass to the array_shift() function the name of the array whose first element you want to ____________________
remove
Within a function, you can end the function and pass the result back to the calling statement by coding a/an ________________ statement.
return
In PHP, function name duplications are likely to occur because all functions have global _____________.
scope
The ____ argument indicates that a cookie can only be transmitted across a secure Internet connection using HTTPS or another security protocol.
secure
When using the MVC pattern, the ________________ statement often works better than an if/else statement in the controller.
switch
The ltrim and rtrim functions let you ________________ all spaces from the front or back of a string.
trim
The ____________________ function removes array elements and other variables.
unset()
With a hidden form field you can only include the name and ____________________ attributes.
value