Re: invoking unrelated constructor's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am learning PHP & came across that code in the book, hence thought to
clear the doubt. Inheritance would have solved that issue.

Could you please tell me which "design patterns" are recommended.

Thanks
Sachin Raut


On Fri, Nov 22, 2013 at 7:45 PM, Stuart Dallas <stuart@xxxxxxxx> wrote:

> On 22 Nov 2013, at 14:03, Sachin Raut <imsachinraut@xxxxxxxxx> wrote:
>
> > Thanks Stuart. Will remember your advise.
>
> Great, but you didn’t answer the question. What you’re looking to do here
> is really bad design, and there’s definitely a better way of doing it.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
>
> > On Fri, Nov 22, 2013 at 7:06 PM, Stuart Dallas <stuart@xxxxxxxx> wrote:
> > On 22 Nov 2013, at 13:33, Sachin Raut <imsachinraut@xxxxxxxxx> wrote:
> >
> > > 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.
> >
> > Your PHP book is out of date. Methods must now be declared as static if
> they are to be called statically, otherwise you cannot call them statically.
> >
> > The more important question is why the heck you would want to do what
> you’re trying to do? Calling another class’s constructor seems like a
> really really really bad idea, not to mention completely daft.
> >
> > -Stuart
> >
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
> >
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux