PHP Flashcards

1
Q

PHP can be run without a server.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Who originally authored PHP, and when?

A

Rasmus Lerdorf, in 1994.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

PHP is an open source product.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PHP is a client-side scripting language whose scripts are embedded in HTML documents.

A

False, PHP is a server-side scripting language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is PHP statically or dynamically typed?

A

Dynamic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

PHP is purely interpreted, meaning what?

A

PHP is executed directly by the interpreter without being compiled into machine code first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In what version of PHP was OOP functionality first added?

A

PHP 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In what version of PHP was object handling completely rewritten?

A

PHP 5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How is internal PHP code embedded in HTML documents?

A

By inserting the code between the “<?php” and “?>” tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is external PHP code embedded in HTML documents?

A

<?php include(“script.php”); ?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three ways of writing comments in PHP?

A

//…, #…, or /* … */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

PHP variable names must always be preceded by a ‘$’.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The following unassigned (unbound) variable has what value?
$x;

A

Null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The following are both valid print methods:
print “Hello World! < br >”;
echo “Hello World! < br >”;

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The following are both valid print methods:
print (“Hello World! < br >”);
echo (“Hello World! < br >”);

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The following will print the value stored in $x:
echo “The value is: $x”;

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The following will print the value stored in $x:
echo “The value is: “ + $x;

A

False - this will print ‘0’, as the compiler attempts a numerical addition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The following will print the value stored in $x:
echo “The value is: “.$x;

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The following will print the value stored in $x:
echo “The value is: “, $x;

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How many primitive types are there in PHP?

A

8.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the 3 categories of primitive types in PHP?

A

Scalar types, compound types, and special types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are the 4 (primitive) scalar types in PHP?

A

Boolean, Integer, Double, String.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the 2 (primitive) compound types in PHP?

A

Array and Object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are the 2 (primitive) special types in PHP?

A

Resource and NULL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

7E2 and 7e2 are both valid numeric literals in PHP.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

7,000 and 7,000,000 are both valid numeric literals in PHP.

A

False, neither are.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

7.2E-2 is a valid numeric literal in PHP.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

0x0A and 0X0A are both valid numeric literals in PHP.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

By default, how many bytes per character in PHP?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

The native PHP string is “Unicoded” (outputted as a Unicode string).

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

You cannot output a Unicode string in PHP.

A

False - you can.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What character is used to delimit String literals in PHP?

A

Either single or double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the difference between single and double quote delimiters for string literals in PHP?

A

They do not allow the same substitutions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What will be printed to the html document?
echo ‘he\’s cool \n’;

A

he’s cool \n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What will be printed to the html document?
$x = ‘me’;
echo ‘he\’s “cool\” like $x’;

A

he’s “cool\” like $x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What will be printed to the html document?
echo “he\’s cool \n”;

A

he\’s cool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What will be printed to the html document?
$x = ‘me’;
echo “he\’s \“cool\” like $x”;

A

he\’s “cool” like me

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What will be displayed on the browser?
$sum = 100;
print(‘The sum is $sum <br> Is that ok?’);

A

The sum is $sum
Is that ok?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

The following will result in how many empty lines between characters ‘a’ and ‘b’?
print(“a\n”);
print(“<br>”);
print(“b\n”);

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is the output of the following code on the browser?
$a = “Guns N\’ Roses”;
print(“\$a”);

A

$a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Boolean values in PHP are case senstive.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

In PHP, 0 and 0.0 evaluate to Boolean false.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

In PHP, both “” and NULL evaluate to Boolean false.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

In PHP, “0” evaluates to Boolean false.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

In PHP, ‘0’ evaluates to Boolean false.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

The following code sets $x’s value to what?
unset($x);

A

NULL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

When does the following expression return true?
isset($x);

A

When $x’s value isn’t NULL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

NULL is coerced to 0 if the context specifies a number.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

NULL is coerced to “null” if the context specifies a string.

A

False - it is coerced to an empty string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What is phpinfo()?

A

phpinfo() is a predefined function that outputs information about the PHP configuration and environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What does round(5.5) return?

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What does PHP’s built in srand() function do?

A

srand() seeds a random number generator. There is no reason to do this past PHP 4.2.0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What does rand() return if we don’t pass any arguments?

A

Nothing, rand() requires 2 arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Which PHP function rounds doubles up, and which rounds down?

A

ceil() and floor().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

Which php function returns the absolute value of a number?

A

abs()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Which PHP functions return the smallest/greatest values out of a list of values?

A

min() and max()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

What operator is used in PHP for string concatenation?

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Can commas be used for string concatenation?

A

No, but echo can take multiple arguments separated by commas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

The second line exhibits a valid method of concatenation.
$a = “Hello “;
$a .= “World!”

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

What does strlen($str) return?

A

The length of $str.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

What does strcmp($str1, $str2) return?

A

0 if the strings are identical, a negative number if the first string “comes” before the second (in the ASCII sequence) and a positive number if the second string comes before the first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

What does strpos($str1, $str2) return?

A

The character position of $str2’s position in $str1, if it exists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

What does substr($str, $int) return?

A

The substring of $str, from index $int to the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

What does chop($str) return?

A

$str but will all whitespace removed from its end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

What does trim($str) return?

A

$str but will all whitespace removed from both ends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

What does ltrim($str) return?

A

$str but will all whitespace removed from its beginning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

What does strtolower($str) return?

A

$str in all lowercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

What does strtoupper($str) return?

A

$str in all uppercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

what does the following code output?
echo substr(“Apples are good”, 7, 2);

A

ar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

what does the following code output?
echo strcmp(‘a’, ‘c’);

A

-2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

What does strpos($str1, $str2) return if $str2 isn’t found in $str1? (PHP)

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

What does the following code output?
$str = ‘Look at the sea’;
$str[strlen($str)-1] = ‘e’;
echo $str;

A

Look at the see

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

What is the output of the following code?
$x = “hi”[1];
echo $x;

A

i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

In PHP, how many ways are there to explicitly convert (cast) a value?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

Write 3 ways to cast the value in $x to an integer in PHP.

A

(int) $x
intval($x)
settype($x, “integer”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

How many ways are there to determine the type of a variable in PHP? What are they?

A

2 - gettype($x) or is_integer($x).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

gettype($x) returns what if $x’s type can’t be determined?

A

“unknown”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

When can a string be converted (or coerced) to an integer? (PHP)

A

If it begins with an integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

In PHP, when can a string be converted (or coerced) to a double? (4 cases)

A

If the string begins with a double, a period, an e or an E.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

If a PHP string does not begin with a sign or a digit, then what number is it implicitly converted (coerced) to?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

What is NULL coerced to if the context specifies a number?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

What is NULL coerced to if the context specifies a string?

A

”” (empty string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

What is the output of the following?
$str = ‘5.1’;
print($str+1);

A

6.1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
84
Q

What is the output of the following?
$str = ‘5.1’;
print((int)$str);

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
Q

What is the output of the following?
$str = ‘5.5’;
print((int)$str);

A

5 - casting rounds down.

86
Q

Which is faster, echo or print?

A

echo - but only slightly.

87
Q

When using printf, what does %10s specify?

A

A character string field of 10 characters.

88
Q

When using printf, what does %6d specify?

A

An integer field of six digits.

89
Q

When using printf, what does %5.2f specify?

A

A float or double field of 5 digits before the decimal, and 2 digits after the decimal.

90
Q

What’s the difference between != / == and !== / === ?

A

!= & == are type coercing.

91
Q

Are >= & <= type coercing?

A

Yes.

92
Q

Which is coerced when a string and a number are compared?

A

The string is coerced to a number, and numeric comparison is used.

93
Q

If two strings are compared, PHP will never coerce both into numbers.

A

False - both will be coerced into numbers if both “look like” numbers.

94
Q

Comparison operators should generally be used to compare strings.

A

False - strcmp() is (generally) preferred.

95
Q

and, or, and xor are valid PHP Boolean operators.

A

True.

96
Q

Which has higher precedence between && / || and the ‘and’ / ‘or’ Boolean operators?

A

&& / || have higher precendence.

97
Q

switch ($val) {
case “0”: echo “zero”; break;
default: echo “not zero”;
}
Is this a valid PHP switch statement structure?

A

Yes.

98
Q

The following constructs a valid array:
$list = array(1, 3, 5, 7, 9);

A

True.

99
Q

The following constructs a valid array:
$list = array(1 => “Cessna”,
2 => “C210”,
3 => 1960,
4 => “sold”);

A

True.

100
Q

The following keys can be replaced with strings:
$list = array(1 => “Cessna”,
2 => “C210”,
3 => 1960,
4 => “sold”);

A

True.

101
Q

foreach($list as $key) allows you to iterate over the keys in $list.

A

False, this notation will iterate over the values, where each value can referred to by the $key variable.

102
Q

Write a foreach loop that iterates over the keys AND values of a $list.

A

foreach($list as $key => $value)

103
Q

The following allows you to iterate over keys:
foreach($list as $key =>)

A

False - this results in a parse error.

104
Q

Where is the value ‘5’ placed in $list?
$list[] = 5;

A

At the last available index.

105
Q

$nums = array(1, 2, 3);
Write a single line of code that assigns each value in $nums to its own variable, such as $a, $b, $c.

A

list($a, $b, $c) = $nums;

106
Q

What method accepts an array, and returns an array of the keys from the passed array?

A

array_keys()

107
Q

What method accepts an array, and returns an array of the values from the passed array? (PHP)

A

array_values()

108
Q

What values are used as keys for the arrays constructed by array_keys() and array_values()?

A

Integer numbers, starting from 0.

109
Q

What method returns true if the passed value exists as a key in the passed array?

A

array_key_exists()

110
Q

What is the order of parameters passed to array_key_exists()?

A

array_key_exists($key, $list)

111
Q

How can you delete an array in PHP?

A

unset($list);

112
Q

The following is valid:
unset($list[4]);

A

True.

113
Q

How do you check whether $list is an actual array?

A

is_array($list)

114
Q

How do you check whether the value $x exists in $list?

A

in_array($x, $list)

115
Q

How do you get the length of an array?

A

sizeof($list)

116
Q

What is the output of the following code?
$list[4] = 1; $list[1] = 17;
$list[2] = 3; unset($list[2]);
foreach($list as $key => $value)
echo “$key $value <br>”;

A

4 1
1 17

117
Q

Create an array of every word in $str (words separated by spaces).

A

explode(“ “, $str)

118
Q

Create a string containing every value in $list (separate each value by a space).

A

implode(“ “, $list)

119
Q

What is the output of the following code?
$list = array(“A”, “B”, “C”, “D”);
echo current($list);

A

A

120
Q

What is the output of the following code?
$list = array(“A”, “B”, “C”, “D”);
echo next($list);

A

B

121
Q

What does each($list) return?

A

A key-value pair of the “current” element. This method however has been deprecated.

122
Q

Write another way to accomplish the following:
$list[] = $x;

A

array_push($list, $x);

123
Q

Write another way to accomplish the following:
unset($list[sizeof($list) - 1]);

A

array_pop($list);

124
Q

sort() sorts the array based off what? Are key/value relationships preserved?

A

sort() sorts the values and removes existing keys.

125
Q

asort() sorts the array based off what? Are key/value relationships preserved?

A

asort() sorts the values and keeps key/value relationships - intended for hashes.

126
Q

When is rsort() used?

A

To sort the values of an array into reverse order.

127
Q

When is ksort used?

A

To sort the elements of an array by the keys, maintaining the key/value relationships.

128
Q

When is krsort() used?

A

To sort the elements of an array by the keys into reverse order.

129
Q

PHP functions can be called before being defined.

A

True - the entire document is parsed prior to execution.

130
Q

Can you overload functions in PHP?

A

No.

131
Q

Can PHP functions have a variable number of parameters?

A

Yes.

132
Q

Can PHP function definitions be nested?

A

Yes.

133
Q

Are PHP function names case sensitive?

A

No.

134
Q

Can the return keyword be omitted from PHP function definitions?

A

Yes - its omission implies a void function.

135
Q

Does PHP crash if more parameters are passed to a function than it is defined to accept?

A

No - the extra parameters are ignored.

136
Q

Does PHP crash if less parameters are passed to a function than it is defined to accept?

A

No - the unmatched formal parameters are unbound (unless they’ve been given default values).

137
Q

In PHP, by default, are parameters passed by value, or by reference?

A

By value.

138
Q

How can you specify a pass-by-reference for a specific parameter in PHP?

A

Precede it with an ampersand:
function f(&$x) { … }

139
Q

In PHP functions, can objects and arrays be returned in the same way as other primitive types?

A

Yes.

140
Q

How can a function be made to return a reference?

A

Preceding the name of the function with an ampersand:
function &f() { … }

141
Q

What is the output of the following code?
$a = 1; $b = 2; $c = 0;
function maxx(&$max,$a,$b) {
if($a>$b) $max = $a;
else $max = $b;
$a = 0;
}
maxx($c,$a,$b);
echo $c.” “.$a;

A

2 1

142
Q

Do function variables live (exist) past the end of the function execution?

A

Normally, no.

143
Q

What is the scope of an undeclared variable in a function?

A

It has the scope of the function.

144
Q

How could you access a variable $x defined outside a function, from within that function.

A

global $x;
(Prior to the manipulation of $x).

145
Q

What is the output of the following code?
$a = 1; $b = 2;
function Sum() {
global $a, $b;
$b = $a + $b;
}
Sum();
echo $b;

A

3

146
Q

What PHP function checks whether a string matches a specified regex? What is the order of its parameters?

A

preg_match(regex, str [, array]);

147
Q

What does the optional 3rd parameter do in preg_match()?

A

Passing an empty array as a third parameter means that array will be filled with all matches of pattern matching operation.

148
Q

What does preg_match() return?

A

A Boolean (either true or false).

149
Q

What PHP method splits a string into an array using a specified regex as a delimiter?

A

preg_split(regex,str);

150
Q

In PHP, forms may be handled by the same document that
creates the form.

A

True.

151
Q

What 2 methods can be used to transmit form data in PHP?

A

GET or POST.

152
Q

How are names associated with their values in a query string?

A

By an equals sign: name = value

153
Q

What types of characters are substituted with something else in query strings?

A

Special characters and spaces.

154
Q

In query strings, what are special characters and spaces replaced by?

A

By % followed by the hex code for that character.

155
Q

What common name must you give to all checkbox widgets to obtain an array of their values.

A

Something followed by ‘[]’.

156
Q

Write a PHP class header for a Person object.

A

class Person { … }

157
Q

How would you define 2 attributes (a1 & a2) within a class definition in PHP?

A

public $a1;
public $a2;

158
Q

Define a constructor for a PHP class, C1, that has two attributes (a1 & a2).

A

public function __construct($a1, $a2) {
$this->a1 = $a1;
$this->a2 = $a2;
}

159
Q

Write a public class method that returns a string containing both its attributes, a1 & a2.

A

public function greeting() {
return “{$this->a1} {$this->a2}”;
}

160
Q

Can class methods be static in PHP?

A

Yes.

161
Q

What keyword should never be used in a static class method in PHP?

A

this (followed by ->)

162
Q

How are cookies created in PHP?

A

setcookie() method.

163
Q

What are the parameters accepted by the setcookie() method?

A

setcookie(cookie_name, cookie_value, lifetime)

164
Q

Can cookies be created at any time?

A

No, they must be created before any other HTML
is created by the script.

165
Q

How could you iterate through all cookies?

A

Using the $_COOKIE array.

166
Q

What does a cookie set look like in the http transaction? (server to client)

A

Set-Cookie: name=value;expires= …;path=/

167
Q

What does a cookie get look like in the http transaction? (client to server)

A

Cookie: name=value

168
Q

With your browser, you can view, delete and block cookies.

A

True.

169
Q

Where are cookies stored (passed)?

A

In the HTTP request header.

170
Q

Set a cookie to expire in a day from now.

A

setcookie(“key”, “value”, time() + 86400);

171
Q

How can you check whether a specific cookie has been set?

A

isset($_COOKIE[“key”])

172
Q

How can you delete a cookie?

A

setcookie(“key”, “”, time() - 1);

173
Q

Does JS have built in ways of setting/getting cookies?

A

No.

174
Q

Write a JS function to set cookies.

A

function setCookie(c_name,value,exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? “” : “;
expires=”+exdate.toUTCString());
document.cookie=c_name + “=” + c_value;
}

175
Q

Create an array of all cookies in JS, similar to $_COOKIES in PHP.

A

ARRcookies=document.cookie.split(“;”);

176
Q

Are cookies returned to all servers?

A

No, only to the servers that created them.

177
Q

Why may systems that depend on cookies fail?

A

If the browser refuses to store them.

178
Q

How are sessions similar to cookies?

A

Holds info about one single user, and passes info between pages.

179
Q

How are sessions different from cookies?

A

Information is stored server side, and session info is deleted after the user has left the website (if not saved).

180
Q

How does PHP track sessions?

A

PHP creates and maintains a session tracking id.

181
Q

Where is the session id stored?

A

Either stored in a cookie or propagated in the URL.

182
Q

What PHP function creates a session id?

A

session_start()

183
Q

Following session id creation, what do subsequent calls to session_start() do?

A

Subsequent calls to session_start() retrieve any session
variables that were previously registered in the session.

184
Q

How do you register a session variable?

A

using $_SESSION[‘var_name’].

185
Q

What restriction is put on the session_start() call if cookie-based sessions are being used?

A

It must be called before outputting anything to the browser.

186
Q

How do you retrieve a session variable?

A

using $_SESSION[‘var_name’].

187
Q

How do you delete a specific session variable?

A

unset($_SESSION[‘name’]);

188
Q

How do you completely destroy a session?

A

session_destroy();

189
Q

Does session_destroy() unset global variables? What about the session cookie?

A

No, but all other data associated with the current session is destroyed.

190
Q

How can session variables be used again following session_destory()?

A

By first calling session_start() again.

191
Q

What method returns a “file pointer”?

A

fopen();

192
Q

What are the parameters of fopen()?

A

fopen(“filename.txt”, “x”);
where x is the use indicator.

193
Q

List all the file use indicators.

A

r, r+, w, w+, a, a+.

194
Q

Describe the ‘r’ use indicator.

A

Read only. File pointer initialized to the beginning of the file.

195
Q

Describe the ‘r+’ use indicator.

A

Read and write and existing file. File pointer initialized at the beginning - read and write operations both move the same pointer.

196
Q

Describe the ‘w’ use indicator.

A

Write only, initializes file pointer to the beginning of the file. Creates the file if it does not exist.

197
Q

Describe the ‘w+’ use indicator.

A

Write and read, initializes file pointer to the beginning of the file. Creates the file if it does not exist. Always initializes file pointer to beginning before writing - destroying existing data.

198
Q

Describe the ‘a’ use indicator.

A

Write only, initializes file pointer to the end of the file if it exists. Creates the file if it does not exist, and puts file pointer to the beginning.

199
Q

Describe the ‘a+’ use indicator.

A

Read and write, creating the file if necessary; new data is written to the end of existing data.

200
Q

How do you check if a file exists?

A

file_exists($filename)

201
Q

How do you close a file?

A

f_close($file);

202
Q

what are the parameters of the fread() method?

A

fread($file_var, $bytestoread)

203
Q

What method returns the size of a file (in bytes)?

A

filesize($file);

204
Q

What method returns the next car of an open $file?

A

fgetc($file)

205
Q

Write a while loop that reads characters until the end of the file.

A

while(!feof($file_var)) {
$ch = fgetc($file_var);
}

206
Q

Use fseek() to jump to the beginning of $file.

A

fseek($file, 0);

207
Q

Use fseek() to jump to the 1000th byte of $file.

A

fseek($file, 1000);

208
Q

Use fseek() to jump 100 bytes ahead of the current position in $file.

A

fseek($file, 100, SEEK_CUR);

209
Q

Use fseek() to jump 100 bytes behind of the current position in $file.

A

fseek($file, -100, SEEK_CUR);

210
Q

Use fseek() to jump 100 bytes behind the end of $file.

A

fseek($file, -100, SEEK_END);

211
Q

Use a PHP function to write “Hello World” to $file.

A

fwrite($file, “Hello World”);

212
Q

Does fwrite() return anything?

A

Yes, it returns the number of bytes written.