Distinguish between arrays within a class and arrays of objects?
|Subject||Object Oriented Programming|
|NU Year||Set: 2.(d) Marks: 5 Year: 2009|
PHP has two compounds (also known as composite) data types: objects and arrays. Compound data types require composition — the process of combining other data types into one “unit.” In purely object-oriented languages, we have to compose data types that in PHP are available to us as primitive types.
When explaining objects and object-oriented programming, I think it is really useful to start by talking about arrays, which are not objects. The fundamental difference between a PHP array and an object is that we can’t change the rules of an array. PHP the language defines what we can and can’t do with an array and there is no way for your PHP program to change that.
Objects on the other hand, have rules defined by the PHP program they are running in. These rules are what we call classes.
While every array plays by the same rule, each object plays by the rules of objects and by the rules of the class used to create them.