tags:

views:

50

answers:

1

I was just reading through a tutorial and they mentioned that Objects in php are just the better way of arrays. I am confused? Can someone clear the concept for me. thanks

+2  A: 

That was more or less true for PHP 4, where there was no actual encapsulation. In fact, objects provide some benefits over plain array:

  • Encapsulation (private and protected members) – easier to preserve invariants.
  • Inheritance – a type inherits the default behaviour of its superclass, you only have to replace the parts that differ.
  • Dynamic dispatch (the method that's actually called depends on the type of variable) – provides decoupling of interface and implementation and abstraction.
  • Less polution of global namespace with functions (less compelling since the introduction of namespaces in PHP 5.3)
Artefacto