SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Should non-conformance be fatal?

    There is an interesting debate taking place on the php internals list. The core of the issue is, PHP4 allowed a signature change to a subclassed method, but starting with PHP5.2, this will produce a fatal error.

    On one hand, this is a violation of the Liskov Substitution Principal and is probably not something I would be inclinde to do anyway. On the other hand, why introduce a fatal error and backwards compatibility issues?

    What are your thoughts?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If PHP4 shouldn't have allowed it in the first place (which sounds like the case to me) then you could consider it a bug in PHP4 which has been 'fixed' in 5.2. Anyone relying on that bug has a problem, sure - but better to force them to fix it now, than leave it as a known defficiency? That's what I think.

  3. #3
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose you could liken this to the pass by reference by default change that occured when the shift to 5 happened.

    I believe that they should start discouraging people from doing it, but not have it produce a Fatal error, a warning at most, a notice at least.

    I mean, there are so many lost souls who learnt OOP using PHP4 and are somewhat thoeoretically crippled as the language they use to program OOP simply ignores OOA&D principles.

  4. #4
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps a notice. I thought "guns don't kill people: people do" was the php way. It feels more like an education issue. Why add to the language?

    I'm beginning to feel that OOP-ists are being subtly victimised. I insist that they also get rid of global variables to even the score

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class extends {
    function 
    f($a) {}

    Well, I would expect that d::f( $a ); would have to be as expected as in c::f( $a ); and if not, an error would be clear to the developer; They have made a mistake, but a notice to me is not enough, you have to stop processing of the script right there and then, since the difference in implementation could be serious - the whole -BEEP- point of fatals, no?

    Notice? Nope, that isn't near heavy enough to make an impact; Well, nothing for the developer to stop what they're doing, and taking notice anyways.

  6. #6
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, although I agree with the reasoning behind throwing an error, I would prefer they started with a E_STRICT warning (say) before moving on to a fatal error. Like a few other decisions in the recent past, this strikes me as something that was not properly dicussed before being implemented.
    Last edited by 33degrees; Aug 2, 2006 at 14:07. Reason: Egregious spelling errors

  7. #7
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    It seems to be part of the general arrogance of the PHP devs. The C hackers work their way through their Java text book, knifing the real users at every page, thinking they are giving the real users a lecture on OO. All without ever realising that Java had the @deprecated docblock and used it.

    The big jump from PHP4 to 5 was just crazy. Downgrading namespaces was just silly. The PHP4.4 reference screw up was bad enough. Then came the SPL with it's pointless Iterator classes. It seems to me that Rasmus is the only PHP dev with any contact with the wider community, and he doesn't use OO. They seem totally cut off. At conferences they just give talks to each other.

    My heart sinks every time they change stuff without a deprecation cycle. It's just rude.

    yours, Marcus

    p.s. The Liskov principle does not rule out optional parameters in the subclass, or even a free form argument list. There is no requirement to exactly match a signature. There is a requirement to send the same errors, but only within the specified contract.

    In languages without explicit contracts, you are left with the implicit contract of the syntax. You could thus argue that as the looser set of arguments should have been rejected, so should the new set, thus reducing the Liskov principle to "the method should have exactly the same inputs and outputs", which is silly. This knackers the whole idea of extending the class.

    Anyway, if Babs had meant that, she would have said it. Really it's an OO design principle, not a language design one. It has no place being in the syntax of the language. Without contracts defining the design, the syntax doesn't know what it's doing.

    p.p.s. How can they enforce this junk, and with a straight face introduce GOTO?
    Last edited by lastcraft; Aug 3, 2006 at 05:02.
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  8. #8
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Then came the STL with it's pointless Iterator classes.
    I've never used most of SPL Iterator classes, so they may or may be pointless, I don't know. However, the SPL's internal Iterator interface certainly is not pointless. PHP 5 introduced object iteration at the core; however, without the Iterator interface it is not possible to let the object decide what & how it should be iterated.

  9. #9
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mcgruff
    I'm beginning to feel that OOP-ists are being subtly victimised. I insist that they also get rid of global variables to even the score


    Quote Originally Posted by lastcraft
    How can they enforce this junk, and with a straight face introduce GOTO
    When I first heard about it being introduced in PHP 6, I thought my colleague was joking.

    Quote Originally Posted by Dr L
    Notice? Nope, that isn't near heavy enough to make an impact; Well, nothing for the developer to stop what they're doing, and taking notice anyways.
    For me, it's the impact that needs to be minimised. Especially if the change would mean that developers would need to revisit old code they've developed months ago.

    I agree that developers are to be made aware that what they are doing is wrong, but not so to break backward compatibility.

    That's what's holding the hosts up from moving up in versions. Some sites would break should they upgrade. As a consequence, new PHP versions are offered by hosts a lot later than sooner, or not at all.

    Notices are hidden in a production setup, but are enabled in a development setup. Any good developer knows not to ignore or supress notices and warnings, so I feel that this should do the job.


    Regards,

  10. #10
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Hi.

    It seems to be part of the general arrogance of the PHP devs. The C hackers work their way through their Java text book, knifing the real users at every page, thinking they are giving the real users a lecture on OO.
    That's certainly the impression I get; features like interfaces, copied from Java, without considering why they're essential there and not in PHP. I'm not sure I agree with your use of the term "real users" though; those of us who care about this type of stuff are most likely in the minority, so our opinions probably don't matter a whole lot.

    Quote Originally Posted by lastcraft
    p.s. The Liskov principle does not rule out optional parameters in the subclass, or even a free form argument list. There is no requirement to exactly match a signature. There is a requirement to send the same errors, but only within the specified contract.
    Yes, and in this case it would makes sense to allow, say, additional optional parameters, although this could be emulated by using func_get_args().

    Quote Originally Posted by lastcraft
    In languages without explicit contracts, you are left with the implicit contract of the syntax. You could thus argue that as the looser set of arguments should have been rejected, so should the new set, thus reducing the Liskov principle to "the method should have exactly the same inputs and outputs", which is silly. This knackers the whole idea of extending the class.
    Well, I think that PHP is moving in the direction of explicit contracts, and stricter typing; certainly the addition of interfaces is a step in that direction. In that context, the decision to raise an error makes sense.

    Quote Originally Posted by lastcraft
    Anyway, if Babs had meant that, she would have said it. Really it's an OO design principle, not a language design one. It has no place being in the syntax of the language.
    I'm not sure about that, in as much as I think the concept is similar to the use of static typing; they're both ways of catching errors at "compile" time. Again, given the direction they seem to be wanting to take the language, enforcing this in the syntax makes sense. I don't agree with the direction, but at least there's some kind of consistency.

    Quote Originally Posted by lastcraft
    p.p.s. How can they enforce this junk, and with a straight face introduce GOTO?
    Because it's the PHP Way?
    And

  11. #11
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by dreamscape
    I've never used most of SPL Iterator classes, so they may or may be pointless, I don't know. However, the SPL's internal Iterator interface certainly is not pointless. PHP 5 introduced object iteration at the core; however, without the Iterator interface it is not possible to let the object decide what & how it should be iterated.
    Calling the main interface Iterator just asked for name clashes. I have at least one PHP 4 to 5 migration log jammed on this. Enumerable would have done fine, although really this should have been a language construct, not an optional library. Allowing classes to implement something like __next() or somesuch would have been a far lighter and more consistent way to do things. If the app develeper wants to implement an interface on top, they could have done it themselves.

    All the stupid RecursiveIteratorIterator junk should be stripped ASAP. It's a mess.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  12. #12
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would agree the SPL is a complete mess but to suggest __next(), et al is not a solution either if you ask me, as the end result will be what we are seeing with the SPL

    As for GOTO, I had thought that was a silly idea all forgotten about? I'm not one to argue with the PHP core developers, but Jesus that really was a stupid idea...

  13. #13
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GOTO has been added to 6. http://oss.backendmedia.com/PhP60
    It has its uses for code generation, imo, and getting cpp style #line too.

    But if anyone hand types one, they need their keyboard took away

  14. #14
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 33degrees
    Well, I think that PHP is moving in the direction of explicit contracts, and stricter typing
    Once that happens, I sincerely hope I'll be able to move to another language, probably Python or Ruby (or maybe Javascript?).

    Quote Originally Posted by 33degrees
    certainly the addition of interfaces is a step in that direction.
    True, and it was (along with type hints) the most stupid move on the part of PHP developers.

  15. #15
    SitePoint Addict
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not only should non-conformance not be fatal -- checks for "conformance" have absolutely no business in the runtime at all. In my view, the runtime should simply execute code it CAN execute and shutup otherwise. Can you imagine your CPU complaining if you used a set of instructions that some noble somewhere happened to deem to be "improper"? Runtimes should do their jobs and not complain when asked to do so.

    OTOH, developers should use a special build of PHP (which has the argumentative and noisy checks) or better, there should be liniting tools and/or proper validity checking tools. The only augmentation I can see for the runtime is to allow the ability to dump a session state (ie: the equivalent of a core dump) on a fatal error (or maybe at user provided checkpoints in the code) so that the data from the dump can be pulled into a suitable debugger/linter or perhaps restarted on a noisy developer build of PHP where it can be examined for problems.

  16. #16
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac
    Quote:
    Originally Posted by 33degrees
    certainly the addition of interfaces is a step in that direction.

    True, and it was (along with type hints) the most stupid move on the part of PHP developers.
    ...
    With all do respect I simple can't understand why type hints and interfaces are a 'stupid move'. The type hints would only be stupid if they weren't optional.

    As long as the strict typing is optional I just can't see anything wrong with it. Especially in large frameworks strict typing comes very handy. Loose typing can then be used in some solve-a-single-problem -scripts.

    I will not even start a debate here why interfaces are useful, since they are so essential part of basic OOP.

  17. #17
    SitePoint Addict
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    As for GOTO, I had thought that was a silly idea all forgotten about? I'm not one to argue with the PHP core developers, but Jesus that really was a stupid idea...
    The thing about GOTO is that it seems stupid to those people who have no use for it; for those who do have a valid use for it, it is the simplest and most effective construct possible. Not everyone's needs are the same as one's own. I say there is nothing wrong with GOTO but there is something wrong with those who would misuse it.

    http://www.stevemcconnell.com/ccgoto.htm

  18. #18
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zYne
    ...
    With all do respect I simple can't understand why type hints and interfaces are a 'stupid move'. The type hints would only be stupid if they weren't optional.

    As long as the strict typing is optional I just can't see anything wrong with it. Especially in large frameworks strict typing comes very handy. Loose typing can then be used in some solve-a-single-problem -scripts.

    I will not even start a debate here why interfaces are useful, since they are so essential part of basic OOP.
    Well, I think it's stupid in the sense that it's effort adding something PHP didn't need, effort better spend fixing things that PHP does need. Considering them an essential part of OOP is a very static-typing-oriented view of what OOP is...

  19. #19
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zYne
    I will not even start a debate here why interfaces are useful, since they are so essential part of basic OOP.
    This is the only thing where you're wrong -- interfaces, as well as static typing, are anything but essential in OOP. They are essential only in statically-typed languages like Java or C++; they have nothing to do in dynamic languages like PHP.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •