stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
PHP Midterm Exam Review Flashcards | StudBud
Explore
/
PHP Midterm Exam Review
PHP Midterm Exam Review
40 terms
·
StudBud Administration
·
37 plays
Imported from external platform
Flashcards
40 cards
F
Practice quiz
P
Host live
L
Questions
40
Answers
1
Which of the following is the correct syntax for defining a function in PHP?
def myFunction() { }
function myFunction() { }
func myFunction() { }
function myFunction { }
2
What is the result of 5 + 3 in PHP?
"5 + 3"
8
53
"8"
3
Cookies are stored on the client’s browser rather than on the server
False
True
4
PRG helps prevent duplicate form submissions by redirecting the user after processing a POST request
False
True
5
It is standard practice in PHP to generate a session ID and store it in a cookie to maintain session state
False
True
6
In PHP, a function can return a value using the return keyword
False
True
7
Which superglobal variable in PHP is used to collect form data sent via the GET method?
$_POST
$_FORM
$_GET
$_REQUEST
8
Which of the following is an example of an associative array?
$arr = [1, 2, 3];
$arr = array("a" => "apple", "b" => "banana");
$arr = "apple, banana";
$arr = (1 => "apple", 2 => "banana");
9
Which operator is used to concatenate two strings in PHP?
&
.
+
,
10
Which of the following are superglobal variables in PHP?
$_GET
$_SESSION
$_POST
$_SERVER
$_FILES
$_COOKIE
11
What does the PRG pattern in web development stand for?
Post/Reload/Generate
Process/Redirect/Get
Post/Redirect/Generate
Post/Redirect/Get
12
How would you access the first element of an indexed array $fruits?
$fruits(0)
$fruits[0]
$fruits->0
$fruits{0}
13
Which of the following are valid ways to output text in PHP?
print
echo
printf
<?=
14
In PHP, single-quoted strings allow variable interpolation
False
True
15
In PHP, the __construct() method is automatically called when an object goes out of scope
True
False
16
Which PHP function returns the length of a string?
size()
length()
strlen()
str_length()
17
Which of the following are valid ways to include a file in PHP?
require
import
include
require_once
mod
include_once
18
How would you access a GET parameter named "user" in PHP?
$user = $_POST["user"];
$user = $GET["user"];
$user = $_REQUEST["user"];
$user = $_GET["user"];
19
Using cookies is always more secure than using sessions because the data is stored on the client side
False
True
20
Which variable name is valid in PHP?
$first name
$first-name
$1stName
$first_name
21
Which is the correct way to declare a variable in PHP?
name = "Alice";
var $name = "Alice";
$name = "Alice";
#name = "Alice";
22
Which of the following is a string in PHP?
"Hello World"
null
true
42
23
Which term describes variables defined inside a PHP class?
Attributes
Methods
Functions
Constants
24
Which of the following is the correct way to define a class in PHP?
class Car { }
new class Car { }
Car class { }
def class Car { }
25
Which of the following is the proper way to open a PHP block?
<script>
<?php
<?
<php>
26
Which of the following correctly declares a public method inside a PHP class?
method drive() { }
function drive() { }
public function drive() { }
private function drive() { }
27
Which PHP function is used to create a cookie?
setcookie()
cookie_set()
set_cookie()
create_cookie()
28
The operator === in PHP is used to check if two values match value and type
False
True
29
Function names in PHP are case-sensitive
False
True
30
PHP sessions are given an expiration date for erasing its saved data
False
True
31
Declaring a property as private in a PHP class means it can only be accessed from within that class
False
True
32
Which line of code correctly adds an element "orange" to the end of the array $fruits?
$fruits.append("orange");
array_push($fruits, "orange");
$fruits[] = "orange";
$fruits.push_back("orange");
33
Which superglobal array is used to
confirm
that a form was submitted via POST?
$_GET
$_SESSION
$_SERVER
$_POST
34
Which PHP function must be called at the beginning of a script to use sessions?
open_session()
start_session()
session_start()
begin_session()
35
Which statement is true about GET and POST methods in HTML forms?
Both send data in the request body
Both send data in the URL
GET sends data in the URL, POST sends data invisibly in the http headers
POST sends data in the URL, GET sends data in the http headers
36
The $_POST superglobal is used to collect form data sent via the URL
False
True
37
The echo statement in PHP is used to display text or variables on the screen
True
False
38
Which of the following creates an indexed array in PHP?
$arr = "apple, banana, cherry";
$arr = array("apple", "banana", "cherry");
$arr = ["apple", "banana", "cherry"];
$arr = {"apple", "banana", "cherry"};
39
The count() function in PHP returns the sum of numbers in an array
False
True
40
How can you effectively delete a cookie in PHP?
Use the unset() function on the cookie’s name
Call session_destroy()
Set the cookie’s expiration to a time in the past
Remove the cookie from the $_COOKIE array