<?php
class A
{
protected $a = 'A';
public function setA($a)
{
$this->a = $a;
}
public function getA()
{
return $this->a;
}
}
class B
{
protected $a;
public function setA(A $a = null)
{
$this->a = $a;
}
public function getA()
{
return $this->a;
}
}
$b = new B();
$b->setA(new A());
var_dump($b);
$c = clone($b);
var_dump($c);
$b->setA(null);
var_dump($b);
var_dump($c);
object(B)#1 (1) {
["a:protected"]=>
object(A)#2 (1) {
["a:protected"]=>
string(1) "A"
}
}
object(B)#3 (1) {
["a:protected"]=>
object(A)#2 (1) {
["a:protected"]=>
string(1) "A"
}
}
Fatal error: Argument 1 must not be null in /in/IbL9W on line 22
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IbL9W on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IbL9W on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/IbL9W on line 5
Process exited with code 255.