tel8618217223380 / prado3

Automatically exported from code.google.com/p/prado3
Other
0 stars 0 forks source link

TComponent has no constructor- All sub-classes should call parent::__construct in their constructor #338

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The TComponent in the current trunk has no constructor, thus descendant classes 
can't call parent::__construct() to preserve a proper constructor chain, 
regardless of actual inheritance hierarchy. This is bad practice.

Also TPageNotFoundEventParameter tries to call parent::__construct() in its own 
constructor, but since neither its direct parent (TEventParameter), nor the 
latter's parent (TComponent) define any, it fails with a PHP error. Triggered 
when you try to open a non-existing page.

Original issue reported on code.google.com by google...@pcforum.hu on 25 Jun 2011 at 5:53

GoogleCodeExporter commented 9 years ago
I've currently removed the offending __construct calls to fix the error, but 
maybe this topic needs some more discussion to ensure a proper decision is 
taken.
So if you're pro or against the introduction of a __construct hierarchy, please 
comment.

IMHO:
adding a lot of empty constructor calls is quite useless; it can help you to 
ensure that you won't miss to call a parent implementation, but it introduces a 
lot of unnecessary overhead. Then, what about a __destruct() hierarchy too?
In reality prefer the c++ approach, where you're forced to have a 
constructor/destructor and the parent::* calls are automatically executed; but 
this is php, and it's designed to work in a different way.

Original comment by ctrlal...@gmail.com on 25 Jun 2011 at 10:03

GoogleCodeExporter commented 9 years ago
Side note: in ticket http://code.google.com/p/prado3/source/detail?r=2990 
javalizard points out a good reason why prado could need a constructor chain.

Original comment by ctrlal...@gmail.com on 25 Jun 2011 at 10:19

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/prado3/issues/detail?id=257

TComponent doesn't have anything in it's constructor _yet_.  These changes to 
chain the constructor/destructor are in place to enable my next set of check 
ins.  The next TComponent checkin requires proper constructor/destructor 
chaining...  it is also proper code form.

If something important were to be place in the TComponent constructor, like I'm 
going to be doing very shortly, these seemingly useless functions suddenly 
become very useful.

Original comment by javalizard@gmail.com on 25 Jun 2011 at 4:04

GoogleCodeExporter commented 9 years ago
I don't think the empty constructors would really add much overhead, since 
Prado's using now cached templates, configuration files, etc., which means that 
the overwhelming majority of objects used during the page cycle are now 
recontructed (save for the first time the template/page is referred) from 
serialized() strings by a call to unserialize(). The latter however does not 
call the constructors when re-creating the objects, therefore any overhead 
inside the constructors won't really affect Prado's performance - except for 
the first pageview and for dynamically constructed object at run-time.

An in-tact constructor chain however is key for proper and easy refactoring of 
both core and 3rd party/extension code, ie. where you can simply change the 
parent/base class of a derived object to add functionality to it or change it's 
behaviour, without having to worry whether the parent class has a constructor 
and/or that it gets called properly - because you can and do always call it in 
derived classes.

Original comment by google...@pcforum.hu on 11 Mar 2012 at 1:03

GoogleCodeExporter commented 9 years ago

Original comment by ctrlal...@gmail.com on 25 Jun 2012 at 1:56

GoogleCodeExporter commented 9 years ago
r3211 This adds a common constructor function to TComponent.  All classes with 
__construct need to call "parent::__construct"

Original comment by javalizard@gmail.com on 7 Nov 2012 at 6:56

GoogleCodeExporter commented 9 years ago

Original comment by ctrlal...@gmail.com on 21 Jan 2013 at 7:03

GoogleCodeExporter commented 9 years ago

Original comment by ctrlal...@gmail.com on 24 Jul 2013 at 1:46

GoogleCodeExporter commented 9 years ago
Moved to github: https://github.com/pradosoft/prado/issues

Original comment by ctrlal...@gmail.com on 1 Oct 2013 at 10:14