What is the output of the following code?
What is the output of the following code?
The code demonstrates object-oriented programming in PHP. The 'Test' class defines a public variable 'var' initialized to 1. An instance of the Test class is then created and passed to the 'addMe' function. Inside the 'addMe' function, the 'var' property of the passed object is incremented by 1. As a result, after calling 'addMe', the 'var' property of the 'Test' instance 't' becomes 2. Hence, when 'echo $t->var;' is executed, it outputs 2.
Confirm, answer is B. You can play this program in any PHP online playgrounds. Program: class Test { public $var = 1; } function addMe(Test $t){ $t->var++; } $t = new Test(); addMe($t); echo $t->var; output: 2
The correct answer is B
The correct answer is B : 2
The correct answer is B : 2
confirmado , se realiza el ejercicio y la respuesta correcta es 2