Edit report at http://bugs.php.net/bug.php?id=43274&edit=1

 ID:                 43274
 User updated by:    miha dot vrhovnik at domenca dot com
 Reported by:        miha dot vrhovnik at domenca dot com
 Summary:            __destruct 2
 Status:             Bogus
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        5.2.5
 Block user comment: N
 Private report:     N

 New Comment:

If a parameter is added and they are not optional I would consider this
a fatal error. Or warning could do just fine just like when normal
method signature changes. Although I would consider not giving all
required params to a function a fatal error...


Previous Comments:
------------------------------------------------------------------------
[2010-12-22 13:40:04] johan...@php.net

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?

------------------------------------------------------------------------
[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

Reply via email to