200-550 無料問題集「Zend-Technologies Zend Certified PHP Engineer」
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());
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());
正解:A
解答を投票する
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());
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());
正解:D
解答を投票する
CORRECT TEXT
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?
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);
正解:
5