You are on page 1of 17

SECTION A OBJECTIVE QUESTIONS (50 marks)

INSTRUCTION: This section consists of 40 objective questions. Answer all questions in the answer booklet.

1.

Which is the definition of PHP: A. B. C. D. A. Processing High Languages PHP Hypertext Processor PHP Hyperlink Processor PHP Hyperactive Programming

2.

The following is the definition of client-side interaction, except A. response to interaction may be more immediate (once the program code has been downloaded). B. C. services are secure (as no information is sent from the browser). reliant on the user having using a specific browser and/or plug-in on their computer . D. affected by the processing speed of the host server.

3.

Which of the following filtering techniques prevents cross-site scripting (XSS) vulnerabilities? A. B. C. D. Strip all occurrences of the string script. Strip all occurrences of the string javascript. Enable magic_quotes_gpc. None of the above.

4.

This is a computer with a web server that serves the pages for one or more web sites. The statement above refers to a________________. A. B. C. D. portal host gateway business service provider

5.

Which of the following tags is not a valid syntax to begin and end a PHP code block? A. B. C. D. <% %> <? ?> <! !> <?php ?>

6.

PHP supports the basic data types of strings, integers, double precision floating point numbers, etc, but is a weakly typed language. What the meaning this statement? A. variables are not declared in PHP, but must be prefixed with a $ sign.

B.

when declaring a variable in PHP, we need to define its type

C.

that variables are tied to a specific data type, and may take any of the data types.

D.

that variables are not tied to a specific data type, and may take any of the data types.

7.

Which of the following is NOT a valid variable name in PHP? A. B. C. D. $number-in-class $number_in_class $nic $NumberInClass

8.

What is the correct way to include a file called external.inc? A. B. C. D. <? php include (external.inc); ?> <? php require (external.inc); ?> <!-include file (external.inc) -> <% include file= (external.inc) %>

9.

Which of the following statement about PHP is false ? A. B. C. D. print cannot take multiple expressions. echo() can take multiple expressions. echo() does not have a return value. none of the above.

10.

Which is the output of PHP Code in Figure 1? <?php $text = <<<EOT The big bang bonged under the bung. EOT; preg_match_all('@b.n?g@', $text, $matches); ?> Figure 1 A. B. C. D. bang bung bong bang bonged bung big bang bong bung big bang bung

11.

Which is the output of PHP Code in Figure 2?


$a=3; $b=21; $c=30; echo $a=$b ? "true\n" : "false\n"; echo "<br/>";echo $b!=$c ? "true\n" : "false\n";

Figure 2 A. true true B. true false C. false false D. true false

12.

Which is a selection control structures? A. B. C. D. for ifelse assignment arithmetic

13.

Which of the following is true about conditional statements? A. if statement - use this statement to select one of many blocks of code to be executed. B. if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false. C. if...else if....else statement - use this statement to select one of many blocks of code to be executed . D. switch statement - use this statement to execute some code only if a specified condition is true .

14.

Which statement is not TRUE for a conditional statement in PHP language? A. If statement can use this statement to execute some code if some specific condition is all true. B. Ifelse statement can use this statement to execute some code if the condition is true. If the condition is not true do something different. C. Ifelse ifelse statement can be used to select one of several blocks of code to be executed. D. switch can be used to execute one of many blocks of code to be executed.

15.

Which language construct can best represent wasted if conditional A. B. C. D. A switch statement without a default case. A recursive function call. A while statement. A switch statement using a default case.

16.

Which statement is TRUE about break and default keywords in PHP language? A. The break keyword is used to break out of the switch() statement block. The default keyword is used to execute a default set of statements when the variable passed to switch () does not satisfy any of the conditions listed within the block. B. The break keyword is used to stop immediately to the lines following it. The default keyword is used to execute a default set of statements when the variable passed to switch () does not satisfy any of the conditions listed within the block. C. The break keyword is used to break in the switch () statement block. The default keyword is used to stop default set of statements when the variable passed to switch () does not satisfy any of the conditions listed within the block. D. The break keyword is used to set of statements when the variable passed to switch () does not satisfy any of the conditions listed within the. The default keyword is used to stop default block break in the switch () statement block.

17.

Which statement shall be instead in the PHP Code in Figure 3 to display the output? <?php $alpha = 'abcdefghijklmnopqrstuvwxyz'; $letters = array(15, 7, 15); foreach($letters as $val) { /* What should be here */ } ?> Figure 3 A. B. C. D. echo chr($val); echo asc($val); echo substr($alpha, $val, 2); echo $alpha{$val};

18.

Which statements describe the PHP Code of the program in Figure 4? <?php $headers = getallheaders(); foreach ($headers as $name => $content) { echo "headers[$name] = $content<br />n"; } ?> Figure 4 A. B. C. D. will show all the request headers will disable all the request headers give error does not output anything

19.

Which of statement describe the while statement that allows to create a condition when it returns to true and start looping? A. To add both the increment and decrement sign at the bottom of the code. B. C. D. To add some variable at the above of the code. To add statements break in the code. To add the looping if..else statement in the code.

20.

A class can be built as an extension of other classes using a process known as inheritance. In PHP, how many parents can a child class inherit from? A. B. C. D. one two depends on system resources three

21.

Which is the correct syntax to create an object? A. B. C. D. $object_name = new class_name(); $object => class name; $object => new class_nama.method; New class_name object;

22.

Which parameter would you pass to fopen() in order to open a file for reading and writing? A. B. C. D. w r a t

23.

Which of the following function is used to change the root directory in PHP? A. B. C. D. choot() change_root() cd_root() cd_r()

24.

Which is the output of the PHP Code in Figure 5? <?php $sample = "example"; $tranc = &$sample; $tranc = "output"; echo $sample." "; echo $tranc; ?> Figure 5 A. B. C. D. example output example example output output output example

25.

How many times will the function counter() executes when in the PHP Code in Figure 6? function counter($start, &$stop) { if ($stop > $start) { return; } counter($start--, ++$stop); } $start = 5; $stop = 2; counter($start, $stop); Figure 6 A. B. C. D. 3 4 5 6

26.

Which is the output of the code in Figure 7? $a = 2; $b = 3; $c = ($a++ * ++$b); Figure 7 A. B. C. D. 0 5 8 4

10

27.

Given that the elements in an associative named Car are Perdana, Persona and Wira. Which PHP Code displays the associative arrays use the values as keys and assign sum values to all the cars? A. B. C. $cars=array("Perdana","Persona","Wira); $cars = array("Perdana "=>10, "Persona"=>30, "Wira"=>30); $cars[0]="Perdana"; $cars[1]="Persona"; $cars[2]="Wira"; D. $cars1="Perdana"; $cars2="Persona"; $cars3="Wira";

28.

Given the following code, what will be the value of $a in Figure 8? $a=array(a,b); array_push($a,array(1,2)); Figure 8 A. B. C. D. array('a', 'b', 1, 2) array(1, 2, 'a', 'b') array(array(1, 2), 'a', 'b') None of the above

29.

What will the following script output in Figure 9? <?php 1. $array = array ('3' => 'a', '1b' => 'b', 'c', 'd'); echo ($array[1]); ?> Figure 9 A. B. C. D. 1 B C A warning.

11

30.

Which is the output from PHP Code in Figure 10? <?php $array = range(1,4); foreach($array as &$value) { } foreach($array as $value) { } print_r($array); ?> Figure 10 A. B. C. D. Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 4 ) 2, 3, 4, 4 Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 ) 2, 3, 4, 5

31.

Modify code the below, put this echo $myArray to Line 4 in PHP Code in Figure 11. Identify new output this code. <?php $myArray = array('Ali','Abu,'Ahmad'); print "<pre>"; print_r($myArray); print "</pre>"; ?> Figure 11 A. Array ( [0] => Ali [1] => Abu [2] => Ahmad B. C. D. Array([0] => Ali[1] => Abu[2] => Ahmad) Array([0] => Ali[1], Abu[2], Ahmad[3]) $myArray

12

32.

Identify output based on code show in Figure 12 if statement $rest = substr("abcdef", 0, 1); is replace on Line 3. <?php $rest = substr("abcdef", -1); $rest = substr("abcdef", 0, -1); -----Line 3 echo $rest; ?> Output: abcde

Figure 12 A. B. C. D. a ab abc abcd

33.

What happens when a form submitted to a PHP script contains two elements with the same name? A. They are combined in an array and stored in the appropriate super global array B. The value of the second element is added to the value of the first in the appropriate super global array C. The value of the second element overwrites the value of the first in the appropriate super global array D. The second element is automatically renamed

34.

How are session variables accessed? A. B. C. D. Through $_GET Through $_POST Through $_REQUEST None of the above

13

35.

Which statement describe the set cookies in PHP A. B. C. D. Setcookie(cookie_name, cookie_value); Setcookie("cookie_name", "cookie_value", time()+3600); Setcookie("cookie_name", "cookie_value",time()+3600); Setcookie("cookie_name", "cookie_value", time());

36.

The corresponding address of a localhost is______________. A. B. C. D. 128.0.0.1 255.255.255.0 10.0.44.200 127.0.0.1

37.

Which code connects application server to MySQL database? A. B. C. D. mysql_connect("localhost"); dbopen("localhost"); mysql_open("localhost"); connect_mysql("localhost");

38.

Which of the following is not an SQL aggregate function? A. B. C. D. SUM MIN MAX CURRENT_DATE()

14

39.

Which statement explains the performance of the PHP Code segment in Figure 13? <?php require_once("myclass.php"); myclass::mymethod(); ?> Figure 13 A. B. C. D. Calls the mymethod method in the class statically. Creates an instance of myclass and calls the mymethod method. Generates a syntax error Defaults to the last-created instance of myclass and calls mymethod()

40.

Which is the output for script in Figure 14? <?php classmy_class { var $my_var; function _my_class ($value) { $this->my_var = $value; } } $a = new my_class (10); echo $a->my_var; ?> Figure 14 A. B. C. D. Null Empty 10 An error

15

SECTION B

QUESTION 1

(a)

Explain the comparisons between ASP and PHP in the following context: i. ii. iii. Type of supported database Language in page being used Type of supported web server (6 marks)

(b)

List the rules for naming a variable in PHP. (2 marks)

(c)

State FOUR (4) differences between GET and POST method. (2 marks)

(d) Write PHP code to print student name and registration number. (2 marks)

(e)

Write PHP syntax to produce the following outputs by using $teks = Web Programming, i. ii. iii. iv. WEB PROGRAMMING Text length is 15 Programming word in the position on 4 in the text Displaying the word Programming (8 marks)

(f)

Write PHP code to print odd numbers between 1 -20 using While statement. (5 marks)

16

QUESTION 2

(a)

PHP MyAdmin is software that can be used to manipulate MySQL. List THREE (3) advantages of using PHP MyAdmin (3 marks)

(b)

Write a HTML syntax based on Figure 15.

Figure 15 (5 marks)

(c)

Write the HTML tag for a form and identify the attributes. (4 marks)

(d)

Write a PHP program to compare the values of 3 numbers and display the numbers in ascending order .Given that a, b and c are variables with the values of 10, 4 and 8 respectively. a = 10, b = 4, c = 8 (8 marks)

17

(e)

Figure 16 is the SQL Table called Profile. Write SQL statement for each of the following information.

Figure 16 i. Add ( MOHAMMAD AZRUL BIN HISYAM, POLITEKNIK JOHOR BAHARU,02DUP10F2089, 9112102344, JPH ) in the table ii. Change MOHAMMAD ALIFF BIN AIMAN ic_no from 2147483647 to 910203102259 iii. Delete MOHAMMAD ALIFF BIN AIMAN profile (5 marks)

18