Unit 3 Flashcards

1
Q

What is the purpose of a constructor (__construct) in a PHP class?
A. To destroy an object
B. To create a database connection
C. To initialize object properties upon instantiation
D. To call the parent method

A

Answer: C

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

Which keyword allows an object to refer to itself inside a class method?
A. self
B. this()
C. this
D. $this

A

Answer: D

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

What does encapsulation in OOP help you achieve?
A. Faster execution of PHP scripts
B. Separating HTML from PHP
C. Controlling access to object properties
D. Creating global variables

A

Answer: C

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

Which visibility keyword restricts access to class properties only within the class itself?
A. public
B. protected
C. private
D. readonly

A

Answer: C

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

Which method would you use to retrieve the value of a protected property in a class?
A. A setter
B. A mutator
C. An accessor (getter method)
D. A constructor

A

Answer: C

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

What is the difference between require and include in PHP?
A. include runs faster
B. require throws an error and stops if the file isn’t found
C. require works only in OOP
D. No difference

A

Answer: B

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

Why is require_once commonly used for including classes?
A. It allows dynamic class generation
B. It only runs if the file doesn’t exist
C. It prevents the same file from being included multiple times
D. It runs scripts asynchronously

A

Answer: C

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

In MVC architecture, what is the responsibility of the Model?
A. Handling user interactions
B. Rendering the UI
C. Managing application data and business logic
D. Redirecting between views

A

Answer: C

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

In MVC, which file typically receives and responds to form submissions?
A. Model
B. Controller
C. View
D. CSS

A

Answer: B

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

In PHP namespaces, what symbol is used to separate parts of a namespace?
A. /
B. :
C. \
D. .

A

Answer: C

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

Which of the following correctly creates a new object from the Profile class inside a namespace PhpDevelopment?
A. new PhpDevelopment.Profile();
B. new \PhpDevelopment\Profile();
C. Profile::new(‘PhpDevelopment’)
D. import PhpDevelopment.Profile;

A

Answer: B

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

In the MVC conversion example, what does the controller file do first?
A. Renders a view
B. Executes the model’s convert function
C. Creates a view object
D. Validates a form

A

Answer: C

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

In the converter app, which method was used to return calculated values from the model?
A. calculate()
B. __convert()
C. convert()
D. result()

A

Answer: C

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

What does is_numeric() do in the convert() function of the model?
A. Ensures the result is rounded
B. Checks if input is a number
C. Converts km to miles
D. Limits decimal points

A

Answer: B

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

Which file stores your page title and connects the controller to the view?
A. model.php
B. footer.phtml
C. controller.php
D. index.php

A

Answer: D

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

Why is $_SERVER[‘PHP_SELF’] used in an HTML form’s action attribute?
A. To redirect users to the homepage
B. To prevent CSRF attacks
C. To post form data back to the same script that displayed the form
D. To log server request info

17
Q

What is the main reason for including the Bootstrap CSS framework in the MVC template?
A. To simplify PHP form handling
B. To automatically generate controllers
C. To provide consistent and responsive UI styling
D. To store object properties

18
Q

In an MVC project, why might define(‘WWWROOT’, ‘http://yourdomain/…’) be used in a PHP config file?
A. To encrypt user passwords
B. To shorten image filenames
C. To build absolute paths for assets like images and CSS
D. To force PHP to reload views

19
Q

What is the purpose of the var_dump() function in PHP?
A. To remove variables from memory
B. To create readable HTML output
C. To display structured info about variables (type & value)
D. To format strings for HTML output

20
Q

In the MVC calculator app, where should the arithmetic logic be implemented?
A. In the controller
B. In the view
C. In the model (Calculator.php)
D. In the form action

20
Q

Why should you reuse files like converter.phtml and converter.php when building the calculator?
A. Because they are simpler than HTML
B. To reduce development time by adapting a working MVC structure
C. Because calculator logic requires conversion formulas
D. Because Bootstrap only works with those files

20
Q

Which <select> option value would the user choose to perform multiplication in the calculator?
A. add
B. +
C. times
D. *</select>

21
Q

What will the following code output?
$b = 3.1;
$c = true;
var_dump($b, $c);
~~~
A. float 3.1 true
B. 3.1 true
C. float(3.1) and bool(true)
D. float:true

22
Q

In the calculator model, which method would typically handle the actual arithmetic?
A. calculate()
B. compute()
C. operate()
D. convert()

A

Answer: A** *(or as named in implementation)

23
What does the `explode()` function in PHP do? A. It breaks the server into processes B. It parses HTML into chunks C. It splits a string into an array based on a delimiter D. It removes all whitespace from a string
Answer: C
24
Which of the following would correctly split the expression `"7 * 3"` into parts in PHP? A. `explode(" ", "7 * 3")` B. `split("7 * 3")` C. `parse("7 * 3")` D. `implode(" ", "7 * 3")`
Answer: A
25
Where in the MVC pattern should `var_dump($_POST)` be placed for debugging form input? A. In the view file B. In the model file C. Right after `if (isset($_POST['submit']))` in the controller D. Inside a hidden form field
Answer: C
26
What would be a sensible fallback if the user submits an invalid expression like `7 +` into the enhanced calculator? A. Display `0` B. Display raw code C. Display an error message D. Skip and redirect
Answer: C
27
Why is Bootstrap included in the MVC calculator application? A. To perform math operations faster B. To validate PHP form submissions C. To apply responsive styling and consistent design to form controls D. To debug calculator logic
Answer: C