Sachin Raut
2013-11-22 13:33:52 UTC
Query relate to constructors
Dear Friends,
I am reading PHP book & it says that unrelated constructors can be invoked
as follows.
<?php
class A
{
function __construct()
{
echo "This is A's constructor";
}
}
class B
{
function __construct()
{
A::__construct();
echo "This is B's constructor";
}
}
$obj=new B();
?>
But i am getting an error "Non-static method A::__construct() cannot be
called statically".
Can someone please throw some light if there is anything i am missing in
above code.
Thanks
Sachin Raut.
Dear Friends,
I am reading PHP book & it says that unrelated constructors can be invoked
as follows.
<?php
class A
{
function __construct()
{
echo "This is A's constructor";
}
}
class B
{
function __construct()
{
A::__construct();
echo "This is B's constructor";
}
}
$obj=new B();
?>
But i am getting an error "Non-static method A::__construct() cannot be
called statically".
Can someone please throw some light if there is anything i am missing in
above code.
Thanks
Sachin Raut.