CSCI 315 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Once a session is started, which superglobal variable can be used to get and set the user's data for a session? Question options: $_COOKIE $_SESSION $_GET $_USER

$_USER

Which of the following statements is NOT a valid way to create a timestamp named $birthdate that represents December 2, 1969? Question options: $birthdate = mktime(0, 0, 0, 12, 2, 1969); $birthdate = mktime(12, 2, 1969); $birthdate = strtotime('1969-12-02'); $birthdate = strtotime('12/02/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: Question options: $cart[0]['itemCost'] $cart['itemCost'][0] $cart[$item['itemCost']] $item[$cart['itemCost']]

$cart[0]['itemCost']

To refer to a public property named categoryName for an object that's referenced by $category, you code Question options: $category->categoryName $category->$categoryName $category::categoryName $category::$categoryName

$category->categoryName

To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code: Question options: $days = new DateInterval('P90D'); $due_date = date(); $due_date = $due_date->add($days); $days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days); $days = new DateInterval('P90D'); $due_date = date(); $due_date = $due_date + $days; $days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date + $days;

$days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days);

Which parameter of the session_set_cookie_params() function can be set so the cookie is only available on an HTTPS connection? Question options: $lifetime $path $secure $domain

$secure

Which character is used before an argument to specify that the variable is being passed to a PHP function by reference? Question options: % & @ #

&

Which of the following is NOT an escape sequence used in double-quoted strings in PHP? Question options: /n /t /c /r

/c

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] . "|"; } Question options: 141.95|312.95|411|10.95| 141.95|212.95|312.95|10.95| 141.95|212.95|411|312.95| 10.95|

141.95 | 212.95 | 312.95 | 10.95 |

If a request is not sent, a session will end by default after ________________ have passed. Question options: 2 hours 5 minutes 24 minutes 30 seconds

24 minutes

What output would be produced by the code below? $names = array('Ron Burgundy', 'Brick Tamland', 'Champ Kind', 'Veronica Corningstone', 'Brian Fantana'); echo $names[1]; Question options: Ron Burgundy Brick Tamland Champ Kind Veronica Corningstone

Brick Tamland

To call a static method named randomize in a class named Cart, you code Question options: Cart->randomize() Cart->$randomize() Cart::randomize() Cart::$randomize()

Cart::randomize()

________________ 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. Question options: Bookmarks Favorites Cookies Status bars

Cookies

If the date is December 25, 2017, what output would be produced by the code below? echo date('M. d, Y'); Question options: 12/25/2017 Dec. 25, 2017 December 25, 2017 12/25/17

Dec. 25, 2017

If the date is December 25, 2017, what output would be produced by the code below? echo date('F d, Y'); Question options: 12/25/2017 Dec. 25, 2017 December 25, 2017 12/25/17

December 25, 2017

An array that uses strings as indexes in PHP is known as a/an ________________ array. Question options: non-numeric associative illegal imaginary

associative

Which of the following is a function that is passed as an argument to another function? Question options: callback anonymous restricted value

callback

If you create a function that passes an argument by reference, the function Question options: can change the original variable without using a return statement can change the variable and pass it back by using a return statement can't change the variable must make a copy of the variable before it changes it

can change the original variable without using a return statement

Which PHP function can be used to check if a specified class has been defined? Question options: get_class() is_a() class_exists() property_exists()

class_exists()

Which of the following is a nested function that has access to the outer function's local variables? Question options: closure global stacked illegal

closure

A/an ________________ is a special method within a class that is executed when a new object is created from the class.: constructor

constructor

Which PHP function returns the number of elements in an array? Question options: count() length() max_index() num_elements()

count()

Which of the following functions would you use to define a constant that stores an array in PHP 7.0 or later? Question options: array_constant() constant_array() define() define_constant()

define()

Which method of a DateTime object can be used to determine an amount of time between two dates or times? Question options: diff() datediff() datebetween() add()

diff()

A fundamental concept of object-oriented programming that groups related data and functionality in a class is called ____________________. Question options: encapsulation portability inheritance normalization

encapsulation

A subclass can ____________ the superclass by adding new properties and methods. Question options: destruct extend clone create

extend

Variable substitution is carried out by what process that converts a variable's value to a string? Question options: decimation interpolation coercion encapsulation

interpolation

The $_SESSION variable for a session Question options: is a regular array is an associative array is an object is a cookie

is an associative array

A variable declared inside a PHP function would be considered a ____________ variable. Question options: local global moduler block-level

local

To create an object from a class named Cart that requires two arguments, you code Question options: new Cart($arg1, $arg2) new Cart(arg1, arg2) Cart_constructor($arg1, $arg2) Cart_constructor(arg1, arg2)

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]; Question options: Ron Burgundy Veronica Corningstone Brian Fantana none of these

none of these

When you use object-oriented techniques to implement the MVC pattern, the methods of the model return the data as either arrays or Question options: classes objects properties result sets

objects

When a new class extends a superclass, it inherits the properties and methods of the superclass. Then, it can Question options: override the inherited properties override the inherited methods delete any of the inheritied properties delete any of the inherited methods

override the inherited methods

When creating functions, you can include ______________ that are located inside parentheses after the function name. Question options: parameters returns brackets comments

parameters

A cookie that does not expire when the user closes his or her browser is a(n) ________________ cookie. Question options: session persistent perpetual eternal

persistent

Which of the following are variables that store the data for a class? Question options: methods properties destructors brackets

properties

By default, the properties of a PHP class are ____________. Question options: private protected public colorful

public

To code a constructor for a class named Cart that requires two arguments, you start with this code: Question options: public function Cart($arg1, $arg2) { public function __construct($arg1, $arg2) { private function Cart($arg1, $arg2) { private function __construct($arg1, $arg2) {

public function __construct($arg1, $arg2) {

To code a method within a class that sets the value for a private property named $name based on the argument that's passed to it, you start with this code: Question options: public function setName() { public function setName($value) { private function setName() { private function setName($value) {

public function setName($value) {

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 Question options: private methods to set and get their values public methods to set and get their values a constructor to set and get their values a destructor to set and get their values

public methods to set and get their values

A "natural" comparison of two values Question options: is case-sensitive is case-insensitive puts both "09" and "9" before "10" puts "10" before both "09" and "9"

puts both "09" and "9" before "10"

A ________________ is a special type of array that implements a first-in, first-out collection of values. Question options: shift pop stack queue

queue

Which of the following functions should you use to get a random number if security is a concern? Question options: rand() mt_rand() random() random_int()

random_int()

If you want to round a number within an arithmetic expression, which function should you use? Question options: number_format() round() sprintf()

round()

Which term describes locations in the code that have access to a variable? Question options: lifetime category scope data type

scope

Which PHP function can be used to end a session? Question options: session_start() session_stop() session_destroy() session_remain()

session_destroy()

To delete a cookie, you Question options: delete the $_COOKIE variable use the delete_cookie() function use the remove_cookie() function set the cookie's value to an empty string and its expiration date to a time in the past

set the cookie's value to an empty string and its expiration date to a time in the past

Which PHP function is used to create a cookie? Question options: setcookie() $_COOKIE() create_cookie() make_cookie()

setcookie()

Which of the following is a PHP function that shuffles the values in an array in a random order? Question options: reverse_sort() shuffle() rand_sort() array_rand()

shuffle()

A ________________ is a special type of array that implements a last-in, first-out collection of values. Question options: shift pop stack queue

stack

Which PHP function returns the number of characters in a string? Question options: len() strlen() countchars() substr()

strlen()

The easiest way to add the values in an array is to use Question options: a for loop a foreach loop the array_sum() function the sum_array() function

the array_sum() function

When you use the substr() function to extract a substring from a string, you need to at least pass an argument that gives Question options: the characters in the substring that you're looking for the starting position of the substring the length of the substring the separators for the substring

the starting position of the substring

A ______________ is an integer that represents a date and time as the number of seconds since midnight, January 1, 1970. Question options: timestamp intdate date_format checkdate

timestamp

By default, all arguments passed to PHP functions are passed by ________________. Question options: value reference sequence read access

value

When you create a DateInterval object, you pass it one argument that specifies one or more of the following: Question options: years, months, days hours, minutes, seconds years, months, days, hours, minutes, seconds years, months, weeks, days, hours, minutes, seconds

years, months, days

You can deal with gaps in an array in all but one of the following ways. Which one is it? Question options: Use the array_values() function to remove all gaps and re-index the array. Use a foreach loop to process the array, which skips elements that contain nulls. Use a for loop that contains extra code that skips elements that contain nulls. Use the array_fill() function to replace all gaps in the array with empty strings.

Use the array_fill() function to replace all gaps in the array with empty strings.

Timestamps will encounter a(n) _______ problem if they are not converted to DateTime objects. Question options: Y2K Y2K38 Y10K Y69K

Y2K38

Which of the following statements about associative arrays is NOT true? Question options: You can use the count() function to return the number of elements in the array. You can use both integer and string indexes with an associative array. You can use a foreach loop to access the values of an associative array but not the indexes You can delete elements from an associative array.

You can use a foreach loop to access the values of an associative array but not the indexes

Which of the following statements about an array of arrays is true? Question options: Both indexes in an array of arrays must be integer indexes An associative array can't be used as an array within another array. All of the arrays within an array must have the same number of elements. You can use both for loops and foreach loops to work with an array of arrays.

You can use both for loops and foreach loops to work with an array of arrays.

In PHP, function name duplications are likely to occur because Question options: namespaces create logical function groups all the functions for an application have to be stored in the same file all functions have global scope most programmers use the same naming conventions for functions

all functions have global scope

Which of the following is a PHP function for sorting arrays? Question options: sort() rsort() krsort() all of these

all of these

Which of the following is a parameter of the setcookie() function? Question options: $name $value $expire all of these

all of these

Which of the following is a way to assign a string to a variable in PHP? Question options: single quotes double quotes heredoc all of these

all of these

Which of the following is considered a scalar value? Question options: string literal numeric literal Boolean value all of these

all of these

Which type of PHP function does not have a name? Question options: orphan anonymous inherent variable

anonymous

When you call a function, you can pass ________________ as values that correspond with the parameters of the function. Question options: returns arguments null references cookies

arguments

Which of the following is a PHP function that is used to count the number of times each value in an array is used? Question options: array_count_values() isset() num_elements() count_values()

array_count_values()

Which PHP function returns an array with the elements of two or more arrays in one array? Question options: array_merge() array_slice() array_splice() array_fill_both()

array_merge()

Which of the following functions removes the next element in a LIFO array (also known as a stack)? Question options: array_shift() array_unshift() array_push() array_pop()

array_pop()

Which of the following is a PHP function that returns the sum of the elements in an array? Question options: array_sum() add_elements() array_product() elements_sum()

array_sum()

You can use the ________________ variable within a class to refer to the current object that has been created from the class

$This

To get the value of a cookie, you can use the autoglobal ______________ variable. Question options: $_COOKIE $_SESSION $_GET $_EAT

$_COOKIE

Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this: Question options: $i = strpos($name, ', '); $first_name = substr($name, 0, $i); $last_name = substr($name, $i+1); $i = strpos($name, ', '); $first_name = substr($name, 0, $i); $last_name = substr($name, $i+2); $i = strpos($name, ', '); $last_name = substr($name, 0, $i); $first_name = substr($name, $i+1); $i = strpos($name, ', '); $last_name = substr($name, 0, $i); $first_name = substr($name, $i+2);

$i = strpos($name, ', '); $last_name = substr($name, 0, $i); $first_name = substr($name, $i+2);

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? Question options: $message = $employee[0] . " is " . $employee[1]; $message = $employee[1] . " is " . $employee[2]; $message = $employee["name"] . " is " . $employee["age"]; $message = $employees[0]["name"] . " is " . $employees[0]["age"];

$message = $employee["name"] . " is " . $employee["age"];

Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this: Question options: $name = implode(', ', $name); $last_name = $name[0]; $first_name = $name[1]; $name = implode(', ', $name); $last_name = $name[1]; $first_name = $name[0]; $name = explode(', ', $name); $last_name = $name[0]; $first_name = $name[1]; $name = explode(', ', $name); $last_name = $name[1]; $first_name = $name[0];

$name = explode(', ', $name); $last_name = $name[0]; $first_name = $name[1];

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. Question options: $number = mt_rand(1000,500000); $number = mt_rand(100,50000); $number *= 10; $number = mt_rand(1,500); $number *= 1000; $number = mt_rand(10,5000); $number *= 100;

$number = mt_rand(10,5000); $number *= 100;

Code example 10-1 $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: Question options: 0 years, 1 months, and 7 days overdue. -0 years, -1 months, and -7 days overdue. 1 month and 7 days overdue. $overdue_message won't be set because the if clause won't be executed

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'); Question options: 12/25/2017 Dec. 25, 2017 December 25, 2017 12/25/17

12/25/17

If the date is December 25, 2017, what output would be produced by the code below? echo date('n/j/Y'); Question options: 12/25/2017 December 25, 2017 Dec. 25, 2017 12/25/17

12/25/2017

If the date is December 25, 2017, what output would be produced by the code below? echo date('n/d/Y h:i A'); Question options: 12/25/2017 12/25/2017 12:00 AM December 25, 2017 12/25/17

12/25/2017 12:00 AM

________________ provides a way to create a new class based on an existing class. Question options: Overriding Inheritance Portability Chaining

Inheritance

The ________________ of a string specifies the number of characters that it contains.

Length()

To avoid the duplication of function names, you can Question options: Use namespaces Use libraries Store function files in lower-level directories Use include paths

Use namespaces

Given this function: $compare_function = function(float $left, float $right) { return $left <=> $right; }; what will happen when the following statement is executed? $result = $compare_function(12.5, 12); Question options: The function will return -1. The function will return 0. The function will return 1. The function will throw an exception because 12 isn't a float value.

The function will throw an exception because 12 isn't a float value.

Given this function: function get_tax(int $subtotal, float $tax_pct) : float { $tax = $subtotal * $tax_pct; return $tax; } what will happen when the following statement is executed if strict types mode is set? $tax = get_tax(10.5, .08); Question options: The function will return NULL because the subtotal isn't an int value. The function will return 0 because the subtotal isn't an int value. The function will truncate $subtotal to 10 and return .80. The function will throw an exception because the subtotal isn't an int value.

The function will throw an exception because the subtotal isn't an int value.

The function that follows returns function coin_toss() { if (mt_rand(0, 1) == 0) { $coin = 'heads'; } else { $coin = 'tails'; } return $coin; } Question options: a random value between 0 and 1 a value of either 0 or 1 a value of either "heads" or "tails" a reference to the $coin variable

a value of either "heads" or "tails"

Which of the following is NOT true about type declarations? Question options: They can be used to declare the return type of a function. They can be used to declare the type of a parameter. They can be used with or without strict types mode. They were introduced with PHP 7.

They were introduced with PHP 7.

The ________________ function returns the largest value of the two or more arguments that are passed to it.

Max()

What is stored in $message by the code that follows? $message = "The file is in \"C:\\My Documents\""; Question options: The file is in C:\My Documents The file is in "C:\My Documents" The file is in C:\\My Documents\ The file is in "C:\\My Documents\"

The file is in "C:\\My Documents\"

What is the default name of a session cookie in PHP? Question options: PHPSESSID SESSIONID SESSIONCOOKIE session_name

PHPSESSID

______________ properties and methods are inherited by a sublass but not accessible outside of the class. Question options: Protected Public Private Read only

Protected

Code example 10-1 $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 Question options: a TimeStamp object a DateTime object a DateInterval object a TimeInterval object

a DateInterval object

When you use session tracking, each HTTP request includes Question options: a URL that stores the session ID a cookie that stores the session ID a cookie that stores the session data a cookie that stores the session ID and the session data

a cookie that stores the session ID

Which method of passing a variable allows the function to change the value of the variable? Question options: by scope by value by reference by name

by reference

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: Question options: foreach ($country_codes as $name[code]) { foreach ($country_codes as $code => $name) { for ($country_codes as $name[code]) { for ($country_codes as $code => $name) {

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 Question options: $_ARGUMENTS variable $_FUNCTION variable func_get_args function func_num_args function

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: Question options: function randomize($&parm1, $parm2 = 5) { function randomize($parm1 = 5, $&parm2) { function randomize(&$parm1, $parm2 = 5) { function randomize($parm1 = 5, &$parm2) {

function randomize(&$parm1, $parm2 = 5) {

Which PHP function returns a string with all special HTML converted to the HTML entity? Question options: htmlentities() encode_entity() converthtml() htmlencode()

htmlentities()


Set pelajaran terkait

HADM 3210 Prelim 1 WHQ Questions

View Set

Chapter 6: Management and Leadership

View Set

EMT chapter 7 quiz - lifespan development

View Set

Nursing Management: Patients With Hematologic Disorders

View Set