Diving into PHP: Day 15
Continuing with our OOP review, today, we’ll create a very simple “calculator” class that should give you a better idea of how abstracting your code to its own class can save you a great deal of time. We’ll also take a look at the helpful “__construct” method, as well as creating variables. Enjoy!
Day 15: Calculator Class
- Subscribe to the Theme Forest RSS Feed.

















I have been waiting for this video. I saw all the episodes. Thanks jeff.
Just noticing that in all of your PHP files you never close the tag. That is just bad practice IMO, you should always close your tags!
Other than that a good, simple tutorial.
Nice tutorial. Its cool how all OOP languages are all pretty much the same.
@Dave – It’s not bad practice at all. If you’re working with a class file which is 100% PHP, it’s better practice NOT to close it.
@Jeffrey
Really? I always thought people didn’t close their class files (that are all PHP) because it was some form of short hand or just laziness. But it’s actually good practice not to? Good to know!! Time to update some of my files..
@Scott – Don’t worry about updating your files. It’s not a big deal either way.
awesome as usual keep it up!
Good tutorial Jeff! Can’t wait to dive into more advanced PHP OOP techniques!
I was waiting for this thanks for great series
Hey im new here. was wondering where the rest of the days are??
Nice, I have been waiting for this for a long time now! Glad to see your using Intype its such a great/ powerful editor really light too, also has many built in tab trigger(snippets).
@jeff Just an observation — when you pub your jeff-way.com site you may want to empahsize the hyphen.. I made an error in assumption and went to “jeff.way.com” which, as you know, is NOT you. However, except for a substantially different “gimme your email” attitude, it is under construction and not at all clear that it is NOT you. I’m sure that many of your unsuspecting readers are unwittingly giving the guy their email addresses before they realize it is not you.
Nice to hear your voice again jeff
, really good tutorial, i have learnd many things from all these diving into php:D
Thanks for wonderful tutorial….
Hey Jeff, is there an easy way to get to a list of 1-15 on this series?
Great tut Jeff!
What are the most common uses of classes?
I really should start watching these this weekend, in fact I am scheduling it in right now…between barbecues and parties and band practice
@Pikatzu You can find most of the ‘Diving Into PHP” screencasts here http://net.tutsplus.com/videos/screencasts/diving-into-php/
Hi Jeff,
I still don’t understand the reason behind classes
I know that a lot of applications use classes but im not sure why.
I can understand when you mentioned the __construct ability.
That makes scene for database.
However apart from that why would you use it and not just separate functions?
It just seams like lots of extra text to type for the ability just to group the functions?
Clint.
Why would it be bad practice to close tags in classes and good practice not to close them???
hay man
i new in this site
and i no speak english so good
but your PHP video is amazing
and i dont anserstend all the class stuff
but today is my like day
plzz continion all the this like this and alot of video OOP
10XXXX
@nouky – I never said it was “bad practice”. It’s perfectly acceptable. But by removing the closing tag, you don’t have to worry about white space issues. Either method is fine.
@nOuky,
If you find it more comfortable to use end tags in classes, that is up to you.
However, when you are working with pure PHP code in a particular file, leaving off the closing tag IS a good habit. If you leave it there, ANY blank space after the tag might be interpreted as a blank line of HTML and often triggers a PHP error message. This is not always true, but because of the possibility of errors, leaving off the last tag is a much safer habit to get into.
Once again Jeff, you hit the nail of the head with this one. Great tut!
Man Jeff, you beat me to it!
Awesomeness!
Another great tutorial, thank you.
Hey, great tut, but I was wondering if you were going to talk about MySQL security as mentioned in previous tutorials?
Thanks Jeffrey!
I’m really understanding this OOP stuff thanks to you.
Awesome! Can’t wait for the next “episode” ^^,
I too would like to hear what you have to say about MYSQL secuirity issues as well, can’t wait for day 16.
Awesome job ! Easy example and easy comment.
@Jeffrey – When I press the TAB key in InType the bundle shortcuts doesn’t work.. I have to go to bundle and keep on clicking on each… any suggestions.?
Great Screen Cast! Just wanted to know if you’re continuing this series?
I’ve gone through your entire Diving into PHP series and it’s great! Thanks so much for your clear and concise explanations. I’ve gone through PHP books and other tutes and you’re are the best. You even managed to get me inspired to take on OOP again. thanks once more for taking the time out to make these!