4 Answers
4

Don't confuse Java's OO with PHP's. Java is a single paradigm language which means that it only does OO. PHP on the other hand is a multi paradigm language, you can either do functional programming or OO or both.

Now there is no such thing as a "bad" implementation of OO. Java's OO is not a definitive implementation that every other language should or must follow. There are some definitive concepts, and both languages fully implement them in their own way (Java since the beginning, PHP since version 5).

So, to answer your question: What CI does and what you are doing with it is right in the PHP world. PHP's arrays are one of its most flexible and useful structures and it's actually a good thing to use arrays over objects when your data are just information (do not carry logic with them). Fully OO code is not the same thing as "only OO code".

If you are starting with PHP do use Java as a reference for good OO practices but do not limit your understanding of PHP because of the "Java does it differently" thing. You can really screw up in both, the paradigm will not save you if you don't get the concepts.

If in any case you find Java more to your liking (as a personal preference) do check out Ruby for web development, they are a little bit more closely related.

Why should we not confuse Java OO with PHP OO? They are pretty much the same, except that PHP has a native array/hash datatype.
–
Martin WickmanMay 28 '11 at 13:06

The implementations are quite similar. I was referring to how they are used in both languages.
–
Yannis Rizos♦May 28 '11 at 16:39

I have an issue in OOP. I want to create OOP design for an application (PHP base), where one object will depends on other objects. How do i handle this in PHP? plz help me...
–
imeNov 26 '14 at 13:49

Example Scenario: Hotel object have Room object's, where a room object have to Date objects... and a Date object have prices for person types. Now how to handle this type of scenario in PHP by OOP base (because there are large data which needs processing at each level).
–
imeNov 26 '14 at 13:52

"usage objects just as arrays will take more memory and CPU." This is not (always) true. An object holding the same amount of data with an array will occupy almost exactly the same amount of memory.
–
Yannis Rizos♦May 27 '11 at 21:26

@Yannis Rizos, yes, objects even can use less memory, edited.
–
OZ_May 27 '11 at 21:37

It's not just that they can use less memory, it's that their memory use is irrelevant because it's trivial compared to other memory performance aspects of the system and to the benefits of using objects. If we cared about memory usage so much, we would never use objects. What we care about is that objects give us better tools to reason about and construct systems.
–
Rein HenrichsMay 27 '11 at 21:44

@Rein Henrichs, I know it, thanks. That's why all words about 'memory' was removed from my answer. I'm not trying to do silly optimization, but I'm sure objects just because they are objects is not a reason for refactoring :) Read my answer, not only comments.
–
OZ_May 27 '11 at 21:49

You don't really pass data around in an OO system -- you pass objects around. The difference is that objects contains behavior as well as data. That is why they call it object oriented and not data oriented.

As long as your don't need behavior with your data, then plain old php arrays are just as good (or bad, depending on your point of view) as value objects.

I think this is just a question of adjustment - there are many implementations of "objects" in programming - Python and Javascript have strikingly different properties. PHP OO is arguably a hack - PHP arrays aren't "objects" in the traditional sense - but they serve an obvious purpose. Unless you want the data to have custom BEHAVIOUR then why use an object?

To give the data a reliable structure. Yep, I can build a function that outputs a particular format/nesting of array but who's to say I don't write another function that modifies it slightly and then passes it on.
–
Matt PottsMay 28 '11 at 0:03

1

sure - then you would need an object to protect variable access - since there are no PHP equivalents of Python tuples for example. But there you go - you've defined the problem, you've just got to use the constructs available to the language... or just learn to live with it's "quirks". I've added a link to my initial post that has an interesting discussion of the problem.
–
sunwukungMay 28 '11 at 12:47