Let me first clarify that I’m not much familiar with PHP language, since I have been working with Java web and Android. Following is a simple PHP class where I’m trying to invoke explicitly a parameterized constructor.
final class Demo
{
private $x;
private $y;
public function __constructor($x, $y)
{
$this->x=$x;
$this->y=$y;
}
public function show()
{
echo "Sum = ", $this->x+$this->y;
}
}
$d=new Demo(10, 20);
$d->show();
It however displays Sum = 0 means that the constructor is not being invoked (In Java, C# and languages alike, it’s very handy to invoke constructors somewhat in such way). How can I then invoke the specified parameterized constructor in the above class?
The name of the constructor is
__construct().__constructor()is just a curious looking method.