Php Objective Questions with Answers for written test exams 4

Question 4
What will the following script output?


class a

{

var $c;

function a ($pass)

{

$this->c = $pass;

}

function print_data()

{

echo $this->$c;

}

}

$a = new a(10);

$a->print_data();

?>

A. An error

B. 10

C. “10”

D. Nothing

E. A warning
Answers 4


Answer D is correct.There actually is a bug in the print_data() function—

$this->$c is interpreted as a variable by PHP, and because the $c variable is not

defined inside the function, no information will be available for printing. Note

that if error reporting had been turned on, either through a php.ini setting or

through an explicit call to error_reporting(), two warnings would have been

outputted instead—but, unless the exam question tells you otherwise, you should

assume that the normal PHP configuration is being used. And in that case, the

interpreter is set not to report warnings.

  







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---