What is the output of the following code?
What is the output of the following code? var_dump(boolval([]));
What is the output of the following code?
What is the output of the following code? var_dump(boolval(new StdClass()));
Which operator needs to be used instead of ??? so that $result equals $value1 if $value1 evaluates to true, an
Consider the following code: $result = $value1 ??? $value2; Which operator needs to be
used instead of ??? so that $result equals $value1 if $value1 evaluates to true, and equals
$value2 otherwise? Just state the operator as it would be required in the code.
Which of the following is NOT true about PHP traits?
Which of the following is NOT true about PHP traits? (Choose 2)
Given the following code, what will the output be:
Given the following code, what will the output be: trait MyTrait { private $abc = 1; public
function increment() { $this->abc++; } public function getValue() { return $this->abc; } } class
MyClass { use MyTrait; public function incrementBy2() { $this->increment(); $this->abc++; }
} $c = new MyClass; $c->incrementBy2(); var_dump($c->getValue());
how can we use both traits A and B in the same class?
Given the following code, how can we use both traits A and B in the same class? (select all
that apply) trait A { public function hello() { return “hello”; } public function world() { return
“world”; } } trait B { public function hello() { return “Hello”; } public function person($name) {
return “:$name”; } }
In the following code, which line should be changed so it outputs the number 2:
In the following code, which line should be changed so it outputs the number 2: class A {
protected $x = array(); /* A */ public function getX() { /* B */ return $this->x; /* C */ } } $a =
new A(); /* D */ array_push($a->getX(), “one”); array_push($a->getX(), “two”); echo
count($a->getX());
What is the output of the following code?
What is the output of the following code? class A { public $a = 1; public function
__construct($a) { $this->a = $a; } public function mul() { return function($x) { return
$this->a*$x; }; } } $a = new A(2); $a->mul = function($x) { return $x*$x; }; $m = $a->mul();
echo $m(3);
What is the output of the following code?
What is the output of the following code? class Number { private $v = 0; public function
__construct($v) { $this->v = $v; } public function mul() { return function ($x) { return $this->v
* $x; }; } } $one = new Number(1); $two = new Number(2); $double =
$two->mul()->bindTo($one); echo $double(5);
What is the output of the following code?
What is the output of the following code? class Number { private $v; private static $sv = 10;
public function __construct($v) { $this->v = $v; } public function mul() { return static function
($x) { return isset($this) ? $this->v*$x : self::$sv*$x; }; } } $one = new Number(1); $two =
new Number(2); $double = $two->mul(); $x = Closure::bind($double, null, ‘Number’); echo
$x(5);