Re: PHP4 vs PHP5 overrides

From: Date: Thu, 17 Mar 2011 03:00:02 +0000
Subject: Re: PHP4 vs PHP5 overrides
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-311895@lists.php.net to get a copy of this message
It's funny how talking or writing about something uncovers things you didn't see before. In an effort to tidy up the code I heeded the original implementors comments and made the methods private (they were previously undeclared). Making them public seems to have fixed the problem. On 17/03/11 13:20, Tom Robinson wrote: > My apologies. I've not seen something I should have earlier. Also the > instance that is behind all of this is and instance of > ActiveRecordFormClass. > > So, in PHP4, the correct overridden method is called: > ActiveRecordFormClass::_dispatchSave(). > In PHP5, the FormClass::_dispatchSave() is called...??? > > BTW I'm tracing this though with xdebug. > > Regards, > > Tom > > Tom Robinson > System Administrator > On 17/03/11 13:06, Tom Robinson wrote: >> Hi, >> >> I'm trying to decipher inherited code (I did not write this) and I'm >> having great difficulty understanding the override of a method in PHP4 >> vs PHP5 >> >> Here's the code: >> >> form.php >> 22 class FormClass >> 23 { >> ... >> /* some method calls to _dispatchSave() */ >> 572 if($this->_dispatchSave($key) === FALSE) >> 573 { >> 574 return FALSE; >> 575 } >> ... >> /* _dispatchSave is defined */ >> 692 function _dispatchSave($key) >> 693 { >> >> arform.php >> 17 class ActiveRecordFormClass extends FormClass >> 18 { >> ... >> /* _dispatchSave is defined */ >> 84 function _dispatchSave(&$key) >> 85 { >> >> In PHP 4.3.9: >> >> The arform.php implementation of _dispatchSave is called >> (i.e.ActiveRecordFormClass::_dispatchSave())in preference to the one >> defined in it's own class. This is the desired call BTW but why does >> this happening? I would expect the parent implementation to be called, >> not a child implementation??? >> >> In PHP 5.1.6: >> >> I get the warning: >> >> "PHP Strict Standards: Declaration of >> ActiveRecordFormClass::_dispatchSave() should be compatible with that of >> FormClass::_dispatchSave() in ..." >> >> which is expected since the parameters are defined differently. As I >> expected, the FormClass::_dispatchSave() implementation is called in >> PHP5. This implementation does not have the desired effect (the >> application crashes). >> >> What is happening? Maybe I'm not seeing something simple. I look forward >> to any responses. >> >> Regards, >> >> Tom >> >> >> >>

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.general (#311895) next »