PHP (MCQs)

Q.86 In PHP, which keyword is used to inherit a class from another class? A. extends B. inherits C. uses D. implements

Shw me The Right Answer

Answer. A
Q.87 What is the purpose of the __construct() method in a PHP class? A. To configure a server B. To create an object from the class C. To initialize an object’s properties D. To delete an object

Shw me The Right Answer

Answer. C
Q.88 What keyword is used to declare a class in PHP? A. class B. object C. new D. struct

Shw me The Right Answer

Answer. A
Q.89 Find the error in the following PHP code: $arr = array(“one”, “two”, “three”); foreach ($ar as $val) { echo $val; } A. Typo in the variable name inside foreach B. Syntax error in array declaration C. No error in the code D. Error in echo statement

Shw me The Right Answer

Answer. A
Q.90 Identify the issue in this PHP code: $str = ‘Hello’; echo $str[10]; A. Trying to access an undefined index B. Syntax error C. No error, it will print ‘Hello’ D. It will print a space

Shw me The Right Answer

Answer. A
Q.91 Why is it recommended to avoid using the PHP closing tag ?> at the end of a file? A. To prevent syntax errors B. To improve performance C. To prevent accidental whitespace or new lines after the tag, which can cause output buffering issues D. To conform to PSR standards

Shw me The Right Answer

Answer. C
Q.92 What is the significance of using the PHP Data Objects (PDO) extension for database access? A. It provides faster query execution B. It is specific to MySQL databases C. It offers a secure, consistent way to interact with different databases using the same interface D. It automatically creates database schemas

Shw me The Right Answer

Answer. C
Q.93 Spot the mistake in this PHP code for sending a POST request using cURL: curl_setopt($ch, CURLOPT_POST, true); curl_exec($ch); A. Not setting the CURLOPT_POSTFIELDS option B. The CURLOPT_POST option is incorrectly used C. curl_exec() is used incorrectly D. No mistake in the code

Shw me The Right Answer

Answer. A
Q.94 Identify the common error in this API request code in PHP: $response = file_get_contents(‘https://api.example.com/data’); A. Not checking for a false response B. Incorrect URL format C. Not setting a user agent D. The function file_get_contents cannot be used for API requests

Shw me The Right Answer

Answer. A
Q.95 In PHP, how can you consume a RESTful API using cURL? A. Using file_get_contents() with the API URL B. Using the cURL functions to make a request and receive a response C. Using JSON encoding and decoding D. Using simple XML loading functions

Shw me The Right Answer

Answer. B
Q.96 How can you send a JSON response from a PHP script? A. json_encode() B. json_response() C. header(“Content-Type: application/json”); echo json_encode($data); D. send_json($data);

Shw me The Right Answer

Answer. C
Q.97 What is the primary role of JSON in web services developed with PHP? A. To structure the layout of a web page B. To act as a query language for databases C. To format and transfer data between client and server D. To encrypt data during transmission

Shw me The Right Answer

Answer. C
Q.98 What is a RESTful API in the context of web services? A. An API that uses XML for data exchange B. An API that allows only GET requests C. An API designed around the principles of REST (Representational State Transfer) D. An API that requires SOAP protocol

Shw me The Right Answer

Answer. C
Q.99 Spot the mistake in this Laravel Eloquent query: $users = User::where(‘age’, ‘>’, 30)->get(); A. The get() method is used incorrectly B. The where clause is incorrect C. There is no mistake D. The model User is likely not defined

Shw me The Right Answer

Answer. C
Q.100 Identify the issue in this Symfony controller method: public function index() { return $this->render(‘index.html.twig’); } A. The method doesn’t specify a route B. The template file extension should be .blade.php C. The method must return a Response object D. No issue in the code

Shw me The Right Answer

Answer. C
Q.101 In Symfony, what is the purpose of a “Service Container”? A. To manage user authentication B. To store and retrieve session data C. To automatically inject dependencies into classes D. To handle database migrations

Shw me The Right Answer

Answer. C
Q.102 Given a Laravel blade template, how can you display a variable passed from a controller? A. {{$variable}} B. <php echo $variable;?> C. @variable D. {!!$variable!!}

Shw me The Right Answer

Answer. A
Q.103 In Laravel, what is a “Route” used for? A. To optimize database queries B. To create links to different pages C. To define URLs and their corresponding actions in the application D. To manage user sessions

Shw me The Right Answer

Answer. C
Q.104 How does the MVC (Model-View-Controller) architecture in frameworks like Laravel and Symfony benefit web application development? A. It enhances the UI/UX design B. It speeds up the database read/write operations C. It separates business logic, presentation, and data access D. It reduces server load

Shw me The Right Answer

Answer. C

You may also like...

Leave a Reply

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