PHP (MCQs)

Q.76 Which PHP function is used to set a custom error handler? A. set_error_handler() B. error_report() C. handle_error() D. trigger_error()

Shw me The Right Answer

Answer. A
Q.77 What is the purpose of the try and catch block in PHP? A. To detect and handle syntax errors B. To manage program flow C. To handle exceptions and errors D. To debug code

Shw me The Right Answer

Answer. C
Q.78 In PHP, which operator is used at the beginning of an expression to suppress error messages that it may generate? A. @ B. # C. $ D. !

Shw me The Right Answer

Answer. A
Q.79 Find the mistake in this PHP code involving object-oriented principles: class Book { public $title; public function __construct(title) { $this->title = title; } } A. Missing $ before parameter in constructor B. Syntax error in property declaration C. No error in the code D. Error in method definition

Shw me The Right Answer

Answer. A
Q.80 Identify the error in the following PHP class definition: class Car { function __construct() { $this->model = ”; } public function getModel() { return model; } } A. Undefined variable model B. Syntax error in constructor C. Missing property declaration D. No error in the code

Shw me The Right Answer

Answer. A
Q.81 What is the result of calling the following PHP code? class Animal { protected $sound = “No sound”; public function makeSound() { return $this->sound; } } class Dog extends Animal { protected $sound = “Bark”; } $dog = new Dog(); echo $dog->makeSound(); A. Bark B. No sound C. Error D. Dog

Shw me The Right Answer

Answer. A
Q.82 Consider the PHP class: class Circle { private $radius; public function __construct($r) { $this->radius = $r; } public function getArea() { return pi() * $this->radius * $this->radius; } } $circle = new Circle(3); echo $circle->getArea(); A. The area of a circle with radius 3 B. Syntax error C. No output D. Error due to private property access

Shw me The Right Answer

Answer. A
Q.83 What will be the output of the following PHP code? class Test { public $prop = ‘Hello’; } $obj = new Test(); echo $obj->prop; A. Hello B. Test C. prop D. Error

Shw me The Right Answer

Answer. A
Q.84 How is a static property accessed in a PHP class? A. With the new keyword B. With the -> operator C. Using the class name and :: D. Using the $this keyword

Shw me The Right Answer

Answer. C
Q.85 What does the final keyword signify when applied to a method in PHP? A. The method cannot be overridden B. The method is the last in the class C. The method is static D. The method is the most important in the class

Shw me The Right Answer

Answer. A

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *