Req #43274 [Opn->Bgs]: __destruct 2
| From: | johannes@php.net | Date: | Wed, 22 Dec 2010 12:40:05 +0000 |
| Subject: | Req #43274 [Opn->Bgs]: __destruct 2 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157233@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=43274&edit=1
ID: 43274
Updated by: johannes@php.net
Reported by: miha dot vrhovnik at domenca dot com
Summary: __destruct 2
-Status: Open
+Status: Bogus
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Linux
PHP Version: 5.2.5
Block user comment: N
Private report: N
New Comment:
If the parent class changes its interface you have to adopt. That
happens not only with __destruct() but with other hanges, too. What
about if they add a parameter such?
Previous Comments:
------------------------------------------------------------------------
[2007-11-13 07:36:17] miha dot vrhovnik at domenca dot com
Description:
------------
Followup to #43264 as i cannot add another comment there :(
__constructor was a typo :( (Old habits die hard.)(I've seen that then
it also dies in constructor if there is no base class)
Why each class should have __destruct, __construct function let's take
another look from another perspective.
I take external class from the web e.g. Smarty
I extend Smarty class, but I need class destructor. As currently Smarty
doesn't have destructor I don't write parent:__destruct into my
destructor. Then Smarty guys decide they need it and somebody at my
company decides that it will upgrade Smarty to that version. In most
cases we just introduced a difficult to find bug.
After making some more research. The same applies if I comment out a
__constuct in base class. Not calling parent::__construct in extended
class if base class gets constructor might result in difficult to find
bugs.
So I beleive that php should provide parent class constructor/destructor
if it doesn't have it already. Well or at least this shouldn't be a
fatal error.
Reproduce code:
---------------
error_reporting(E_ALL);
$c = new extender();
class base
{
public function __construct()
{
//parent::__construct();
}
}
class extender extends base
{
public function __construct()
{
parent::__construct();
}
public function __destruct()
{
parent::__destruct();
}
}
Expected result:
----------------
Not exiting with fatal error. e.g provide default constructor/destructor
functions for every class.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=43274&edit=1