Home > PHP & Programming > Quizzes > PHP Programming Basics Practice Test: Objects and Databases in PHP
PHP Programming Basics Practice Test: Objects and Databases in PHP
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 72% Most missed: “Inheritance is the means by which one or more classes can be derived from a/an _…”
In PHP, objects are flexible and can be lists, trees, widgets, or anything else, and can represent data, structure, or presentation. Databases are powerful and important, but are only suitable for a small subset of the tasks that a web application performs. Objects can make these tasks easier.  PHP Data Objects (PDO) is a database access layer that provides a consistent and fast interface for accessing and managing databases in PHP applications. PDO is a popular option for connecting to and communicating with MariaDB databases in PHP. PDO supports a wide variety of database drivers When... Show more
PHP Programming Basics Practice Test: Objects and Databases in PHP
Time left 00:00
25 Questions

1. Which keyword must be added before $first variable on the third line of the above question to make $second and $first as distinct objects in PHP 5?
2. Which keyword is used to access a static method or property from within the same class(rather than from child)?
3. Which function is used to determine whether the variable’s value is either TRUE or FALSE?
4. At least how many abstract methods must an abstract class contain?
5. Which one of the following is a constant variable?
6. Which one of the following PHP statements is true?
class CopyMe {}
$first = new CopyMe();
$second = $first;
7. In which of the following circumstance should you use a static reference to a non static method?
8. Which characters is used to access property variables on an object-by-object basis?
9. Which one of the following is not a valid class name?
10. Inheritance is the means by which one or more classes can be derived from a/an ___________ class.
11. Which keyword precedes a method name?
12. What will happen if you try to set a value to a constant once it has been declared?
13. Which version of PHP introduced the concept called late static binding?
14. Which one of the following method is invoked when an undefined method is called by client code?
15. Which one of the following variable cannot be used inside a static method?
16. There are two objects-
$product1 = new Shop();
$product2 = new Shop();
Which one of the following statements is right about them?
17. What does PDO stand for?
18. What will be the output of the following PHP code?
class ShopProductWriter
{
public function write( $shopProduct )
{
$str = "{$shopProduct->title}: " .$shopProduct->getProducer() ." ({$shopProduct->price})\n";
print $str;
}
}
$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );
$writer = new ShopProductWriter();
$writer->write( $product1 );
?>
19. How many of the following can be contained in constants?
i) boolean
ii) integer
iii) float
iv) string
20. If you omit the visibility keyword in your method declaration, by default the method will be declared as ____________
21. Which one of the following methods in the exception class, is used to get a nested exception object?
22. Which version of PHP allows you to define constant properties within a class?
23. What will be the output of the following PHP code?
class Person
{
function getName() { return "Bob"; }
function getAge() { return 44; }
function __toString() {
$desc = $this->getName();
$desc .= " (age ".$this->getAge().")";
return $desc;
}
}
$person = new Person();
print $person;
24. Which method is invoked when an undefined property is accessed?
25. Which one of the following keywords are used to define an abstract class?