Free 200-550 Exam Braindumps (page: 28)

Page 27 of 56

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());

  1. Fatal error: Access to private variable MyTrait::$abc from context MyClass
  2. Notice: Undefined property MyClass::$abc
  3. int(2)
  4. int(3)
  5. NULL

Answer(s): D



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";
}
}

  1. Rename the A::hello() method to a different name using A::hello as helloA;
  2. Use B::hello() instead of A 's version using B::hello insteadof A
  3. Use B::hello() instead of A 's version using use B::hello
  4. Rename the A::hello() method to a different name using A::hello renameto helloA;
  5. None of the above (both can be used directly)

Answer(s): B



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());

  1. No changes needed, the code would output 2 as is
  2. Line A, to: protected &$x = array();
  3. Line B, to: public function &getX() {
  4. Line C, to: return &$this->x;
  5. Line D, to: $a =& new A();

Answer(s): C



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);

  1. 9
  2. 6
  3. 0
  4. 3

Answer(s): B






Post your Comments and Discuss Zend 200-550 exam with other Community members:

200-550 Discussions & Posts