Test Midterm Spring 2003 Sample
Instructions: This is a closed book, notes, neighbor examination. Select
the best answer. All output is to be considered what appears in the
browser. DO write on the examination.
- What language is the PHP application server coded in?
- Basic
- C
- Fortran
- Java
- None of the above
- Define Coupling.
- Joining 2 strings together.
- The measure of how dependent two modules are.
- Adding numbers.
- Sharing a variable.
- None of the above
- What will this print?
<?php
$bushApprovalRating = "17.5 percent";
print ("Bush approval rating is: ");
print (intval($bushApprovalRating));
?>
- Bush approval rating is: 17.5
- Bush approval rating is: 17
- Bush approval rating is: 17.5 percent
- 17
- None of the above
- If I create a Web Application that uses MySQL, I can use the same code with any other database without having to change the functions I used to interact with the database.
- True as long as it is a relational database.
- This is true as long as I use the same operation system.
- False because my mom said so.
- False because the functions are specific to a database and the SQL varies slightly from a database to another.
- None of the above
- Modules are organized into objects. The characteristics of these objects are made up of methods and properties. From a programming perspective what characteristic(s) do objects have.
- Functions
- Variables
- Arrays
- Both A & B
- None of the above
- Which is the proper opening and closing tags for a PHP statement?
- <? ?>
- <?php ?>
- <% %>
- All of the above.
- None of the above
- What Syntax mysql is correct
- SELECT *,* FROM name;
- SELECT ID,Summary,Date,Assignee,Submitter,Status,Priority,Kind FROM *;
- INSERT INTO issue (Date) VALUES(now());
- UPDATE issue VALUES Status=$Status;
- None of the above
- Which of the following is not a valid PHP function for scripting using PHP Classes and Objects?
- get_class()
- get_object_vars()
- get_class_methods()
- is_subclass of()
- None of the above
- Which of the PHP extension described in Chapter 13 for databases should you attempt to use if native support for your database doesn't exist?
- InterBase
- Postgres
- JDBC
- ODBC
- None of the above
- What is a database abstraction layer?
- A way to make Oracle work smoother.
- A way to seperate the business logic when switching being different database languages.
- A graphics layer within the database.
- The name of a movie.
- None of the above
- when you declare a class, you are really making a template for the creation of
- funtion
- module
- object
- variable
- None of the above
- Which of the following statements is Not true?
- Objects can be used as an index of an array.
- Arrays can contain multiple data types.
- Multidimensional arrays are just arrays of arrays.
- Only strings and integers can be used to index an array.
- None of the above
- Which is the proper syntax to register the variables "$Name" and "$Count" that you may wish to preserve across page requests?
- session_register($Name);
session_register($Count);
- session_($Name);
session_($Count);
- register_session($Name);
register_session($Count);
- session_register("Name");
session_register("Count");
- None of the above
- which statement will stop all execution?
- return
- halt
- exit
- kill
- None of the above
- What is the value of $var after the following code is executed?
<?php
$var = "Hello World";
$var += 5;
$var++;
?>
- 5
- 6
- "Hello World"
- "Hello World6"
- None of the above
- Which of the following functions returns an array?
1. mysql_fetch_array
2. mysql_fetch_field
3. mysql_fetch_row
4. mysql_fetch_object
- 1
- 1 and 3
- 1 and 2
- 1, 2 and 3
- None of the above
- What does this code output?
<?php
for($index = 2; $index <= 6; $index++) {
print($index - 1);
print(" ");
}
?>
- 23456
- 1 2 3 4 5
- 2-1 3-1 4-1 5-1 6-1
- 2 3 4 5
- None of the above
- What does this code output?
<?php
$myArray = array(1,2,3,"one","two","three", one => 4, two => 5, three => 6);
print("{$myArray[$myArray[one]]}");
?>
- one
- 1
- two
- four
- None of the above
- The process of a function calling itself is
- recursion
- argument
- dynamic call
- return statement
- None of the above
- The following code will produce which of the results below?
<?php
$alpha = array(2, "PHP", 5, 7, 11);
$beta = array("one" => 1, "two" => 2, "three" => "is");
$gamma = array("bob" => "Rules!", 5 => "six", "great!");
print($alpha[1]." ".$beta["three"]." ".$gamma[6]);
?>
- 11 > 6
- PHP is great!
- 2 2 six
- PHP Rules!
- None of the above
- What is the difference between:
1. function double_it( &$x )
and
2. function double_it( $x )
- &$x means the value is passed by reference and $x means the value is passed as an copy
- &$x means the value is passed by value and $x means the value is passed as an reference
- &$x is not alowed in php. $x is the only possible syntax
- $x is not alowed in php. &$x is the only possible syntax
- None of the above
- What will the following code output?
<?php
$i = 0;
do {
print("$i\n");
$i++;
$i = ($i > 5) ? 10: $i;
} while ($i < 7)
?>
- 0 1 2 3 4 5
- 0 1 2 3 4 5 6 8 9 10
- 0 1 2 3 4 5 6 7
- 0 1 2 3 4 5 10
- None of the above
- Which of the following is not a PHP mysql function that returns data rows each in data structure that is either an array or an object.
- mysql_fetch_array()
- mysql_fetch_assoc()
- mysql_fetch_object()
- mysql_fetch_row()
- None of the above
- What is the most popular database used by PHP coders?
- InterBase
- MySQL
- Oracle
- mSQL
- None of the above
- What is the way to comment a block of code lines?
- /* comment
comment
*/
- // comment
comment
//
- # comment
comment
#
- ' comment
comment
'
- None of the above
- How does the PHP language specify the end of a statement?
- :
- \n
- ;
- no character. hitting return is sufficient.
- None of the above
- How many databases does PHP Support?
- 1
- 2
- 3
- many
- None of the above
- No every web site needs to store every piece of content in a database. Which of the below scenarios would most likely NOT require a database?
- Bulletin Board System (BBS) where messages are posted and a message can be related to zero or more other messages.
- Product catalog that contains textual product descriptions and images that correspond to each description.
- A searchable on-line PHP code repository where user can submit PHP code snippets.
- Web-based e-mail. E-mails are stored on a mail server. The web page/PHP code must list, retrieve, compose, and send e-mails specified by the user.
- None of the above
- Where must functions be declared?
- Above the call to it.
- Below the call to it.
- Anywhere.
- In an included file.
- None of the above
- Where is session data stored?
- On the client computer.
- On the server.
- In a cookie.
- It is serialized in the Session ID (SID)
- None of the above
- Which of the following PHP statements will print "Hello, world."?
<?php
print("<H3>Hello, world.</h3>\n");
?>
<?php
PRINT("<H3>Hello, world.</h3>\n");
?>
<?php
PrInT("<H3>Hello, world.</h3>\n");
?>
- All of the above.
- None of the above
- Which of the following regular expressions is best for US zip code validation?
- ^([0-9]{5})(-[0-9]{4})?$
- ^([0-9]{5})(-[0-9]{4})$
- ^([1-9]{5})(-[0-9]{4})?$
- ([0-9]{5})(-[0-9]{4})?
- None of the above
- Which of the following statement about arrays is right?
- You do not have to declare anything about the array before you use it.
- Arrays can only be indexed by integers.
- If you refer to an array element that does not exist, it will evalute to be zero.
- All of the above
- None of the above
- Using the 'global' statement...
- brings a variable into a function's name space, and any changes made to the variable within the function will NOT persist outside of the function. This is just a way to get a variable inside a function without having to pass it as an argument.
- brings a variable into a function's name space, and any changes made to the variable within the function will persist outside of the function.
- is poor programming practice and should always be avoided.
- prevents a variable from being changed. It is like declaring it a constant.
- None of the above
- Which of the following is not an operator?
- --
- ++
- /
- $
- None of the above
- Casting an array as an object...
- is not legal in PHP.
- is not necessary. Arrays are objects.
- has the effect that the elements of the array can be accessed as properties of an object.
- should be avoided because information can be lost upon recasting the the object as an array.
- None of the above
- Given the following lines of script:
$numArray = array(2,4,8,1);
foreach($numArray as $numVal) {
numVal%2==0 ? ++$numVal : $numVal;
}
What will the values in $numArray be at the end of the foreach loop? (starting with index 0)
- 2, 4, 8, 1
- 3, 5, 9, 1
- 1, 9, 5, 3
- 2, 4, 8, 2
- None of the above
- What does the PHP keyword "extend" mean.
- Changes the scope of a variable.
- Formats a variable.
- Allows a class to inherit properties of other classes.
- It changes the length of time a PHP program can run without timing out.
- None of the above
- What will thi scode output?
<?php
$Contact = "Jack"
switch($Contact) {
case "Sara":
print $Contact . "'s phone number is 555-1234";
break;
case "Tim":
print $Contact . "'s phone number is 555-9999";
break;
case "Fred":
print $Contact . "'s phone number is 555-1244";
break;
default:
print "Sorry, I don't know $Contact";
}
?>
- Sara's phone number is 555-1234
- Tim's phone number is 555-9999
- Fred's phone number is 555-1244
- Sorry, I don't know Jack
- None of the above
- How can you have a function remember the value of variable between calls if this variable should remain local for this function?
- By declaring this variable as Global
- By declaring this variable as Static
- By declaring this variable as Local
- By declaring this variable as Private
- None of the above
- Which function is used to fetch all arguments sent to the function as array?
- func_get_args
- func_num_args
- func_get_arg
- func_num_arg
- None of the above
- What happens with session identifier if user rejects cookies?
- The session identifier will be stored on the user's disk;
- The session identifier will be stored on the server;
- The session identifier will not be created;
- The session identifier will be sent in URL
- None of the above
- Session ID numbers are randomly generated by the system's web server and can be stored by an application in a database. The session ID number sould not be used as a primary identifier because ____
- It is valid only for the current session.
- It is lost when the client machine is powered off.
- Non-embedded DBs can not reliably store and dynamically access generated numbers.
- On restarting a httpd, a nonunique randomly generated session ID number may be generated.
- None of the above
- The continue statement is used inside of a loop to:
- continue to execute the statement even if an error occurs
- exit the loop and continue to execute the next code segments.
- stop execution within the loop at that point , and return to begin executing code at the beginning of the loop.
- In a for loop the continue statement increments the counter and continues executing code.
- None of the above
- What will you get if you cast Array as string?
- empty string
- string containing all array elements
- word Array
- NULL
- None of the above
- An alternative to using cookies to pass the session ID among different pages is:
- to declare the session ID variable as global so that it can be seen be all your pages.
- to store the session ID variable in your mySQL database so that it can always be accessed from any page.
- to pass the session ID through links or forms.
- there is no alternative. If cookies are not enabled then there is no way to track information about a user.
- None of the above
- Which of the following statements are true?
- Functions are useful for encapsulating frequently used code. A library of functions can be kept in one or more 'include' files.
- It is easier to update a function used in many places than to modify similiar code in many places.
- A function delcared within a conditional statement is available only after successful execution of the code block which contains the function declaration.
- All of the above
- None of the above
- If a variable in a function has the global operater preceeding
it, which is the following is true.
- It has local scope to the function.
- It can modify a variable outside the function.
- It does nothing to a variable outside the function.
- The global operator is not valid within a function.
- None of the above
- What does this code output?
<?php
$a = 5;
$a += ++$a + $a++;
print $a;
?>
- 16
- 18
- 19
- 17
- None of the above
- To prevent endless loops and long running requests, by default, scripts are limited to how many seconds?
- 30
- 60
- 90
- unlimited , unless changed in the php.ini file
- None of the above
- Where do you define the return type of a function?
- just before the function name
- before the return keyword
- The type is not defined because variable can hold any strings
- The type is not defined because variable can hold any type
- None of the above
- Use dba_firstkey function returns the first key in the database. If the database is Empty. ------ will be returned.
- 0
- null
- False
- Error message
- None of the above
- which of the followings is the output of the following php snippet?
<?php
$count = 5;
$count *= 2;
echo $count;
$count += 1;
echo ' ', $count;
?>
- 10 11
- 52
- 5 8
- 2 1
- None of the above
- When creating an object, what is the statment that should be in place of <statement> in the line below?
$myObject = <statement> anObject("abc", "123");
- new
- object
- create
- No statement is required.
- None of the above
- Which of the following correctly defines a class with a constructor that takes a name and copies it's value to the class's name variable?
class user {
var $name;
function user($name) { $name = $name; }
}
class user {
var $name;
function user($name) { $name = $this->name; }
}
class user {
var $name;
function user($name) { $this->name = $name; }
}
class user {
$name;
function user($name) { $this = $name; }
}
- None of the above
- When placing
<?php print(date("1 F d, Y:)); ?> in a web page where will the code get the date from.
- From a time clock at the National Institute of Standards and Technology (NIST).
- Your time from the computer your browsing the web from.
- From your Internet Service Provider.
- The server in which the web page is stored on.
- None of the above
- What is a recursion?
- This is when a function calls itself.
- The process of a function calling another function.
- The process of a function calling a class.
- The process that takes place when a function is called.
- None of the above
- What is a recursion?
- This is when a function calls itself.
- The process of a function calling another function.
- The process of a function calling a class.
- The process that takes place when a function is called.
- None of the above
- SQL statements and PHP functions are different for each type of database PHP connects to. MySQL vs. Oracle vs. Postgres vs. mSQL and so on. There are tradeoffs in performance when an interpreter attempts allow multi-database independence.
What is the term for a database-independent interpeter?
- ODBC
- Database Abstraction Layer
- Persistence Layer
- 4GL
- None of the above
- The following FOR statement is executed how many times?
for(i = 0; i = 10; i++) {
i++;
}
- Ten times
- Five times
- Once
- Infinite times
- None of the above
- What does this code output?
<?php
$var_name="myGPA";
$myGPA=3.65;
print("$$var_name<br>\n");
?>
- $myGPA
- 3.65
- myGPA
- $var_name
- None of the above
- What will this code output to the browser?
<?php
$Town[] = "Sonoma";
$Town[] = "Santa Rosa";
$Town[] = "San Francisco";
print "I live in $Town[2] and sometimes $Town[0].";
?>
- I live in Santa Rosa and sometimes Sonoma.
- Nothing, the syntax is incorrect.
- I live in San Fransisco and sometimes Sonoma.
- Sonoma, Santa Rosa, San Francisco
- None of the above
- How does a comment begins and ends in PHP?
- /* and */
- /? and ?/
- <" and ">
- /& and &/
- None of the above
- Modules are organized into objects. The characteristics of these objects are made up of methods and properties. From a programming perspective what characteristic(s) do objects have.
- Functions
- Variables
- Arrays
- Both A & B
- None of the above
- The database function mysql_pconnect is the recommended method for connecting to mysql databases. What does the pconnect clause in the function name signify?
- Primary conncection
- Principle connection
- Persistent connection
- Posix connection
- None of the above
- Which of the following will not send text to the browser
- echo
- print
- printf
- printl
- None of the above
- What will the function mysql_pconnect("localhost", "test", "") return if it's failed?
- Empty string: ""
- -1
- FALSE
- NULL
- None of the above
- In PHP how do you determine if a variable has global scope?
- Any variables created outside a function.
- Any variables preceeded by the static keyword.
- Any variables within a function preceeded by the global
keyword.
- All variables.
- None of the above
- What does ^[^a-z]*[0-9]$ match?
- A0, A1... Z9, but not a0,a1 ... z9, 0,..9
- a0, a1... z9, A0,..., Z9 but not 0 ... 9
- A0,..., Z9, 0,..., 9 but not a0,...z9
- a0, a1... z9, 0,..., 9 but not A0 ... A9
- None of the above
- What will this code output?
<?php
$alpha = array(" things ","can ","multi-");
$beta = array("do with ","single","we ");
$gamma = array("<BR />","separate","dimensional ");
$delta = array("When ","What","arrays!","clarity");
$epsilon = array(&$alpha, &$beta);
$zeta = array(&$gamma, " convoluted", &$delta);
$eta = array(&$epsilon, &$zeta);
print $eta[1][2][1];
print $eta[1][1];
print $eta[0][0][0];
print $eta[1][0][0];
print $eta[0][1][2];
print $eta[0][0][1];
print $eta[0][1][0];
print $eta[1][0][0];
print $eta[0][0][2];
print $eta[1][0][2];
print $eta[1][2][2];
?>
- What convoluted things
- we can do with
- multi-dimensional arrays!
- All of the above
- None of the above
- Which one of these uses a valid data assignment operator in PHP?
- $today == "Friday";
- $today := "Friday";
- $today = "Friday";
- $today <== "Friday";
- None of the above
- In PHP script if you put words where the script expects numbers. What values PHP script assing thoes words?
- None
- Ignore
- Take it as a white space
- Zero
- None of the above
- What is the difference between the break and continue statements?
- The break statment will stop a loop and jump outside of it, continue will stop the current execution of the loop and jump to the closing curly brace of that loop.
- The break statement will halt execution of the entire script, continue will halt the execution of the script but allow a message to be displayed.
- The continue statment will stop a loop and jump outside of it, break will stop the current execution of the loop and jump to the closing curly brace of that loop.
- The continue statement will halt execution of the entire script, break will halt the execution of the script but allow a message to be displayed.
- None of the above
- In The following code, what is the first value of $numCount and the last value of $numCount printed to the Browser window?
<?php
$numCount = 1;
print $numCount++ . "<br />\n";
++$numCount;
print $numCount . "<br />\n";
$numCount++;
print $numCount . "<br />\n";
?>
</body>
</html>
- 1
2
- 1
3
- 2
3
- 1
4
- None of the above
- What will this code output?
<?php
$val = 0;
for($counter = 1; $counter <= 10; $counter++) {
if($counter%2 == 0) $counter += 2;
if($counter%2 == 1) $counter += 1;
$val++;
}
print($val);
?>
- 10
- 5
- 9
- 6
- None of the above
- What would the browser most likley display from the fallowing code if you entered your name as steve on the previouse form?
<html>
<title> Test Question </title> <body>
Welcome to my test question
<?PHP
echo $name
?>
, I hope your get it right.
</html>
- Welcome to my test question name, I hope your get it right.
- Welcome to my test question $name, I hope your get it right.
- Welcome to my test question steve, I hope your get it right.
- Welcome to my test question <?PHP $name ?>, I hope your get it right.
- None of the above
- What purpose does the constructor of a parent class serve from the child class?
- The parent constructor is inherited by the child class and overrides the child's constructor.
- The parent constructor is inherited along with, and is no different from, the other parent methods.
- The parent constructor is not inherited by the child class.
- The parent constructor is inherited by the child class and it is up to the programmer to specify which constructor is used.
- None of the above
- Which of the interpretations is correct about the following PHP statement:
$userInfo = new reccord("Ana", "41");
- This is how to create an instance of the class "userInfo".
- This instanciates an object of the class reccord and specifies initial values for some of the class variables.
- This statement ensures that each instance of the class being referred to only has two variables.
- This statement adds to new values to the array $userInfo.
- None of the above
- When using the EXTENDS keyword to create one class based on a parent class, what is the effect on a parent class's constructor if the child class also has a constructor?
- There is no effect.
- The parent class's constructor takes precedence.
- The child class's constructor takes precedence.
- The child class's constructor takes precedence, but it is possible to specifically refer to and execute the parent class's constructor as well.
- None of the above
- What will this code output?
<?php
$tomorrow=100;
$anotherDay=200;
if($tomorrow = $anotherDay) {
print("Tomorrow is another day.");
} else {
print("Not Now, Not Never");
}
?>
- Tomorrow is another day.
- Not Now, Not Never
- 300
- It's a beautiful day.
- None of the above
- In chapter 5 we learned there is various types arrays, to collect values into lists. Which of the arrays listed below is NOT a valid array type for collecting values?
- Indexing Arrays
- Multidimensional Arrays
- Casting Arrays
- Functional Arrays
- None of the above
- When performing an operation on two numbers, one of type integer, and the other of type double...
- the integer is first converted to a double and the operation is performed.
- the double is first converted to an integer and the operation is then performed.
- both numbers are first converted to strings and the operation is then performed.
- no conversion takes place. The operation is performed as is.
- None of the above
- When dealing with a submitted form...
- PHP creates variables from each of the form fields. These variables can be treated just like any variable in PHP.
- PHP creates constant variables from each of the form fields. These variables cannot be changed in PHP.
- the programmer must parse the form in order to get at the form fields, which can then be set to variables by the programmer.
- the programmer must call the PHP function get_form_vars to access the form fields.
- None of the above
- What will the code do?
<?php
phpinfo();
?>
- Displays user information.
- It will get user information from a form.
- Displays the php configuration information on the server.
- The code will eat your computer and ruin your motivation.
- None of the above
- What is the output of the following code?
<?php
$var1 = 1;
print(++$var1);
print($var1++);
print(--$var1);
?>
- 222
- 233
- 122
- 223
- None of the above
- Which of the interpretations is correct about the following PHP statement:
$userInfo = new reccord("Ana", "41");
- This is how to create an instance of the class "userInfo".
- This instanciates an object of the class reccord and specifies initial values for some of the class variables.
- This statement ensures that each instance of the class being referred to only has two variables.
- This statement adds to new values to the array $userInfo.
- None of the above
- What is alternative to if - elseif - else structure?
select (root-epression) {
case case-expression:
default:
}
switch (root-epression) {
case case-expression:
else:
}
switch (root-epression) {
case case-expression:
default:
}
select (root-epression) {
case case-expression:
else:
}
- None of the above
- Which of the following is the correct answer about marking PHP code in a web page?
- <?
?>
- <SCRIPT LANGUAGE="PHP">
</SCRIPT>
- <%
%>
- All of the above
- None of the above
- What is the benefit of a class over an array?
- You can include .exe files in a class.
- You can include functions in classes along with arrays.
- You can color them with sticky marshmallow code.
- There is no benefit, an array is move versatile.
- None of the above
- When doing a file upload via an HTML form; you must set the 'type' attribute of the 'input' tag to:
- text
- image
- file
- either B or C
- None of the above