Hacker News new | past | comments | ask | show | jobs | submit login

This is certainly a debate about semantics, but I don't think you mean "semantics." They changed the implementation of objects. And they added new syntax. But they made no changes that affected the old syntax -- except the one I mentioned.



> They changed the implementation of objects

You're implying it was an implementation detail. They fundamentally changed how objects worked, the semantics, that made it completely impossible to move any of my PHP4 code over in a reasonable way.

It is possible to make code, that uses objects, work in both PHP4 and PHP5 but you have to restrict yourself to a subset of both versions.


That's interesting. What were you doing with your PHP4 classes that didn't run in PHP5?


The difference between value semantics and reference semantics is pretty significant. It's almost impossible to do any meaningful OOP without taking that into account. Getting PHP4 to work reasonably requires a lot of work (hence the change in PHP5).

None of the PHP4 frameworks moved over to PHP5 without a lot of re-writing.

My code simply assumed value assignment semantics and changing that everywhere was just too much work. At this moment, I still have sites running PHP4.


I'd love some specifics.

Were you passing around objects and mutating them while expecting the existing object to be unchanged? For example:

  $o = new MyObject()
  $o->important_data = 'clean';
  function foo($give_me_o) {
    $o->important_data = 'dirty';
  }

  foo($o);
  echo $o; // Need this to say "clean"
Because that, literally, is all that changed. Yes, the implementation changed. But PHP4 syntax (including explicit pass-by-reference and class-named constructors) still works in PHP5. That's not an accident. That was by design. Go back and read the discussions.

Frameworks chose to upgrade because you get MUCH better memory management and cleaner syntax from PHP5. But many, many people run PHP4 code in a PHP5 runtime. It works just fine. Because that example I used above -- while it is totally possible you have code like that, that's in practice pretty rare.


You make it sound like it was a small change. In PHP4, you had to be careful to use references everywhere to get "proper" behavior. To return an object out of collection in your function, it better be both declared with a reference and to use a reference whenever you do an assignment or you won't get what you expect.

The potential for subtle bugs with this change is massive.

Your example is very simple. I've got objects with other objects as properties (composition), collections of objects, hierarchies of object references, as well as methods that take objects by reference or by value. Not using references everywhere is so much easier in PHP4 that whenever possible, I did just that.


I guess so, I'm not well-versed in programming nomenclature, I haven't done a CS course.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: