$a = null; echo $a ?? 'default';
Explanation: Null coalescing operator returns fallback.
Dear candidates you will find MCQ questions of PHP here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question
$a = null; echo $a ?? 'default';
Explanation: Null coalescing operator returns fallback.
$a = 0; echo $a ?: 'fallback';
Explanation: Ternary shortcut treats 0 as false.
$a = 'abc'; echo $a[1];
Explanation: String offset access works like array.
echo gettype(NULL);
Explanation: gettype returns 'NULL' lowercase internally shown as 'NULL' or 'NULL string', expected 'NULL'/'null'.
$a = [1,2,3]; echo array_rand($a);
Explanation: array_rand returns random key.
$a = fopen('php://temp', 'r+');
fwrite($a, 'abc');
rewind($a);
echo fread($a, 2);
Explanation: Reads first 2 characters.
class A {
public function __invoke() { echo 'Invoked'; }
}
$obj = new A();
$obj();
Explanation: __invoke allows object to be called like function.
echo '1' + true;
Explanation: true is converted to 1 → 1 + 1 = 2.
Explanation: htmlspecialchars escapes HTML special characters.
Explanation: PDO provides a consistent interface for multiple databases.