Seems fine to me. But not necessary. One of PHP’s advantages compared to Java is the ability to let the programmer decide to work with or without objects, depending on the needs.
It is very useful to learn how to work with objects, but remember that your project requirements is what matters. In small projects a few simple lines of code are usually enough. The larger the project gets, the more you need OOP.
Why do you want to learn to build a website using OOP?
The reasons to use OOP is one of two: You enjoy over-complicating a project simply for the joy of it. Or you are building a flexible and powerful framework that can handle multiple types of websites/services and requires many layers of abstraction.
If it’s #1, then go for it. If it’s #2, you’re better off using a third party framework as they will do far more and better (and most importantly in less time) at that job than what any one person could put together.
It’s one thing to use objects in some situations as they have clear advantages over procedural code with global functions, it’s another to try to force yourself to use objects when it doesn’t make a lot of sense simply for the sake of saying it’s OOP.
I agree with the above. Unless you are wanting to separate some form of complex business logic from display logic, and so on, I see no real need to use oop. However, if you still want to do this as a learning excercise, then why not.
The reason that I want to use OOP is because of two reasons:
First off, I have about 40 websites to maintain for a client.
All those websites use the same database, the same options and the only thing that varies - and has to vary (a lot) - Every site, is the layout.
At first, I created a hyper-dynamic site but it got complex because of the amount of code, OOP does the trick for me.
The second reason is also the reason that I don’t use already-made products. I love to code and I want to get good at it.
I still have much to learn and I won’t learn if I only use already-made products. So, that’s why… maybe silly, but I like it ^^
Array is an internal class. When you use offset operators (the [$offset] syntax) you are invoking methods on the class. See ArrayAccess interface at php.net for details. You also invoked implode, another method, in the second example. The first method above directly concats a string and invokes no methods.