Unit 3 Flashcards
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
Answer: C
Which keyword allows an object to refer to itself inside a class method?
A. self
B. this()
C. this
D. $this
Answer: D
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
Answer: C
Which visibility keyword restricts access to class properties only within the class itself?
A. public
B. protected
C. private
D. readonly
Answer: C
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
Answer: C
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
Answer: B
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
Answer: C
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
Answer: C
In MVC, which file typically receives and responds to form submissions?
A. Model
B. Controller
C. View
D. CSS
Answer: B
In PHP namespaces, what symbol is used to separate parts of a namespace?
A. /
B. :
C. \
D. .
Answer: C
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;
Answer: B
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
Answer: C
In the converter app, which method was used to return calculated values from the model?
A. calculate()
B. __convert()
C. convert()
D. result()
Answer: C
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
Answer: B
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
Answer: D
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
Answer: C
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
Answer: C
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
Answer: C
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
Answer: C
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
Answer: C
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
Answer: B
Which <select> option value would the user choose to perform multiplication in the calculator?
A. add
B. +
C. times
D. *</select>
Answer: D
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
Answer: C
In the calculator model, which method would typically handle the actual arithmetic?
A. calculate()
B. compute()
C. operate()
D. convert()
Answer: A** *(or as named in implementation)