Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics (Retired) Classes and Objects Object Oriented Overview

Bunyod Kh
Bunyod Kh
10,221 Points

Can you explain in a very simple way [if possible with example] why we need this part of PHP? Why we need OOP?

As far as I understood, we can built simple web-sites without OOP PHP. The problem is I can't understand when we need this "part" of PHP? If possible provide some examples of using OOP PHP?

It is very important because I can't understand the topic while I don't know why, wehn and where I need it?

Thanks.

3 Answers

Roy Penrod
Roy Penrod
19,810 Points

Since it's your own app, you get to decide what you want to use. The simple answer is to say "Hey, use whatever woks for you." The hard part is knowing what's going to work for you. :-)

So let's start with the first app you mentioned: Asana. I just took a look at it so it's fresh in my mind.

You're going to use HTML for the structure of the web document.

You're going to use CSS for creating the look and feel of the app.

You're going to use JavaScript to control the front-end behavior of the app. You'll probably want to use the jQuery library and the jQuery UI user interface library for the drag-and-drop functionality Asana has.

Asana doesn't reload the page when it saves data, so you're going to use AJAX to accomplish that. AJAX lets you use JavaScript to connect with a program running on your server, so you can send data to and receive data from the server without ever reloading the web page.

Since you're using JavaScript to communicate with the server, you're probably going to send and receive that data as JSON. JSON stands for JavaScript Object Notation. It's a common way to structure data that can be shared between different programs.

Now, we're finally talking about the back-end.

The most common languages you can use for back-end development are PHP, Ruby on Rails, Python, and JavaScript (via NodeJS). They're all viable back-end languages and they can all connect to the database you're going to use for data storage.

I've personally used PHP more than anything else because it's always done the trick. I'm adding JavaScript to the mix. I've written a few programs in Python (just enough to be dangerous lol), but I've never touched Ruby on Rails.

I don't think you'll go wrong learning any of the languages, but I would caution against starting with Ruby on Rails.

Ruby on Rails is a combination of a language (Ruby) and a framework (Rails). It's a great combination and lets you build web apps quickly, but it hides a lot of the complexity from the programmer.

That's great for an experienced programmer, but it prevents you from learning what's really going on under the hood. And that can bite you in the butt when something goes wrong (and it always goes wrong).

Basically, if you don't understand what Ruby on Rails is really doing, it's just going to seem like magic to you. And magic is impossible to debug because you don't understand it.

If you've got your heart set on Ruby on Rails, go for it. There's a strong community of Rails developers out there that can help you learn what's happening with it.

But if you're still not sure, try learning enough about all of them to write a simple program or two in each of them and see how they work. You'll figure out what you like and what you don't.

As far as databases go, you'll probably want to use mySQL. It's a very popular and capable open source relational database management system (RDBMS).

At it's heart, Asana is an advanced to-do list. Work up to creating a simple to-do list and saving it in a database. That's your first version.

Then add a new feature, like a log-in system so multiple users can each have their own to-do list.

Then add a new feature, like adding a project which lets store multiple to-do lists together.

You get the idea.

Have fun and ask away if you have any other questions.

Roy Penrod
Roy Penrod
19,810 Points

Don't get discouraged, Bunyod. Asana is a very complex app designed and programmed by a team of professionals.

You can't start with something like Asana, but you can end up with it.

Modern software development is about layering complexity. Start with one simple component, then add to it. Then add to it again. And again. And again.

Since you're interested in starting a software development business, I suggest you check out the following two books:

"The Lean Start Up" by Eric Ries.

"Lean Customer Development" by Cindy Alvarez

They'll get you thinking about the business side of software development using a modern approach. They're all about figuring out how to find out what people really want so you don't waste your time building a great product that no one wants to buy.

Bunyod Kh
Bunyod Kh
10,221 Points

Thanks a lot. Im going with php then since I am an absolute beginner.

Roy Penrod
Roy Penrod
19,810 Points

I don't think you'll regret it. But you can always switch if you end up hating it. You'll still have learned something valuable about programming and that will follow you from language to language.

Roy Penrod
Roy Penrod
19,810 Points

The simple answer is that you don't need OOP to write useful computer programs, but it's very useful for managing and hiding complexity in large projects.

OOP lets you write code that acts like a black box. You put something in, you get something out. You don't need to understand how the code works to use it. You just need to know what to give it and what it gives you in return.

A car is a great example. You don't need to understand how the car engine works to start it. You just need to know how to turn the ignition on.

Bunyod Kh
Bunyod Kh
10,221 Points

Thank you for your answer.

One more thing, I was thinking about choosing between ruby and php before I started this track. I'm very interested in building web applications (for eg. task management tools like asana or online movie watching) and I still don't know what is the best way to start getting into it. any advice? thanks in advance.

Roy Penrod
Roy Penrod
19,810 Points

It really depends on your goal. Are you building the app to start your own business? Or are you wanting to work as a web developer for an established company?

Bunyod Kh
Bunyod Kh
10,221 Points

I planning to build app to start my own business.

Honestly, the guy teaching the PHP courses in the track does not do a great job of explaining very much before jumping in head first... he does however (most often than not) get around to explaining what, when, where, and how things are used in a real life example.

Other courses found here have a MUCH better organization and flow to them. They are working on a new set of courses that should remedy much of the confusion caused by the current courses.

I would highly suggest trying to not let not having 100% grasp on future usage get in your way while taking these php courses or you will run into far too many roadblocks. Simply follow along, trying to retain the information in its purest form... just information... and he will get around to explaining. I had to take notes of these things I had questions on... move along and then when he came to explain them, I'd connect the dots.

HOWEVER.... the simplest answer to give you without getting into trying to over teach / put the full course in here is this:

Simple websites or even simple web apps can be built without OOP. However... in this world, simple never lasts. You'll need to build with OOP to build more complex and flexible web apps. Simply put... OOP is there to allow for complexity. :P ....and flexibility.

Bunyod Kh
Bunyod Kh
10,221 Points

Thank you for your answer.

One more thing, I was thinking about choosing between ruby and php before I started this track. I'm very interested in building web applications (for eg. task management tools like asana or online movie watching) and I still don't know what is the best way to start getting into it. any advice? thanks in advance.

With the updates in PHP5 it really makes it a much closer competitor.... and is beginning to once again be taken serious in more circles as an actual programming language.

I started taking on Ruby, and while I can not speak to it overall as I've just started taking on the track about a week ago... it's code flow seems to be a bit more easy to follow that I remember when learning php.

It's again, a choice that really is up to you. There are people that are on one side of the fence or the other... but it really comes down to this... Both will get the job done. How you want to get it done...is how you decide what to use.

If you find that you are the type that can learn both... then maybe try learning both so you have first hand knowledge that will help you decide which to use.