Diving into PHP: Day 14

It’s been a while, but we’re back with Day 14 of our “Diving into PHP” series. Today, we’ll begin researching OOP techniques. We’ll start with a basic overview of classes and functions, and will then move into some more real-world and complicated examples in future tutorials.

Day 14: OOP

Download the Source Code


  • U says:

    Very neat. Glad to see a thourough OOP video tutorial. Looking forward to the next ones..
    But does this end the expressions series already??

  • henry says:

    nice to see this again thoiught you had forgotton about it! keep up the good work Jeff and thanks for all the effort you put into these blogs you maintain

  • B. Ackles says:

    “…in future tutorials.”
    Does this mean you’ll be providing an intermediate php series? I encourage you to do so. These screencasts are super helpful!

    Keep up the good work Jeffrey!

  • Mrn says:

    nice to get going again ;)

  • uknowme says:

    nice to see back on this series :) it wasn’t that long since the last screencast, but believe me for some of us like me it was really a long gap…
    Really expecting the next screencast of this series soon…
    Thanks again Jeffrey!!!

    P.S. : Now we have 7803 readers as of today n counting… We will support u as much as we can for all your time n hard work in bringing these educational/valuable screencasts to all of us :worship: :kudos:

  • stelath says:

    Hi Jeff:
    Is there any specific PHP that you recommend for beginner to intermediate PHP? I have been following all of your “Diving into PHP” series. I think it is nice to have a book to refer to along with the video tuts.

    Great work so far!! Thanks much.

  • Till says:

    Wow! You didn’t forget the php series:) so cool!!

  • Meshach says:


  • CgBaran Tuts says:

    Great series thanks

  • BroOf says:

    Very helpful! Thanks!

  • daniel says:

    your screencasts are the best! i’m very glad you picked up diving into php again, i think these are my favourite ones ;)

  • Vasili says:

    Very nice, I agree with the fact that books always use the person example and it only confuses a person more. If you use a real world example, it’s much easier to catch on.

    One thing that I think you could have including was a brief overview of “$this”.

  • qalih says:

    Oh no, its a mac. I knew there would be a switch one day, its was all the ‘cool’ people have right.

    Good stuff, hope to see more OOP!

  • Jason says:


    Good to see you are back at it with this series. This series has made me subscriber and a reader of this and the other tuts sites.

    PLEASE keep it up! Thank you so much for taking the time to put these out.

  • wrerm says:

    Jeff I must say it’s rather interesting that I just started practicing OOP in PHP and I agree with you that most tutorials give to much for an intro. This was cool. Nuff Respek!

    My next move is to look into extending classes…

  • cooper says:

    “Day 12: Files” :D

  • Viktor says:

    Very nice to finally start with some OOP programming, I have been using it for a while myself but I am not sure if I am doing it the optimal way, anyways. I’d just like to share with you my mysqlclass. I am quite proud of it, but then I am not THAT good at php.


    Feel free to use it if you’d like, and also feel free to mail me suggestions on how to improve it.

  • Adel says:

    Welcome back Jeff.
    it’s been a long while
    thanx man, keep up…

  • Meshach says:


    A quick question, why put “__” before your method name?


  • Ron says:

    I though you can use :: as -> in PHP5 and up. Like:


  • Talon says:

    i love this stuff!

    thanks, Jeff

  • Viktor says:


    If you are refering to the constructor, it is because that is how I’ve learned to write it. I have no idea how much you know but I’ll give it a shot at explaining what a constructor is anyway. :P

    When you start the new classinstance, the constructor will run right away. In PHP5 you write __constructor() but in PHP4 and possibly below, you have to use the same name as the class, for example:

    class myClass {
    #For PHP5
    __constructor() {
    echo “You just opened myClass!”;

    # For PHP4<
    myClass() {
    echo “You just opened myClass!”;


    $myClass = new myClass(); // This would echo out “You just opened myClass!”

    I hate not being able to indent. :P

    Anyways, as I said previously, I am not overqualified when it comes to php, if there are more optimal methods, I probably don’t know about it.

    And sorry if you already knew this and I just explained PHP to someone who knows more than me. :P

  • @Meshach and @Viktor:

    The two underscores before a method (i.e. __construct()) indicate a magic method in PHP.

    These are special methods that have specific functions regarding common uses of classes.

    __construct is called whenever an object is instantiated, allowing the developer to apply settings, create variables, or whatever else needs to be done without requiring the user to call an additional method. For instance:

    $obj = new Object($settings);
    // Do something with the object…

    Is a easier to track than something like this, which does exactly the same thing:

    $obj = new Object();
    // Do something with the object…

    The above examples assume our object looks like this:

    class Object

    public $settings;

    function __construct($settings=NULL)
    $this->settings = $settings;

    public function applyInitialSettings($settings=NULL)
    $this->settings = $settings;


    Hopefully that helps you guys out. There’s an article on my blog about OOP as well that might work well as a supplement to Jeffrey’s screencast.

    Great job on this, Jeffrey! I love this series.

  • tarek says:

    thank’s jeff, actually i have a question out of the scope ,are we obliged to learn those cms like drupal wordpress joomla???
    i heard that we can accomplish those tasks with zend framework.
    is it right

  • Matt says:

    This is what I have been hoping for! Great screencast, Jeff! Looking forward to learning more and watching more tutorials!

    How many more are you planning on doing? I would love to see this go as far as it can. I can’t find any resources better than this for learning PHP!

    Again, great job!

  • Snookerman says:

    Hey Jeff!

    I really appreciate these screencasts and I frequently recommend them to other people. I asked you before if you could put them all together on one page that I could link to and you told me that the page with the first screencast contains links to all other days. Unfortunately that page is not always updated and it’s also really difficult to find. The same goes for the Wordpress tutorials. The first video is way back in the archives and is not even called day one, it’s something about some competition. The point is, it’s not very user friendly. You should create pages for each series, for jQuery and PHP and Wordpress that are updated all the time and you should link to them on the homepage. Just a suggestion that would make thinks much better for everyone.

  • nice work JW !
    keep it up .

  • Scott says:

    Awesome! This series is extremely helpful. I hope you continue it until day 49360.

    Btw, I also agree with Snookerman. A separate page should be created for each series or a link to all the other entries of a series should be included on each of the posts, not just the first one. It would be much easier to navigate through the series that way.

    But regardless, keep up the good work!

  • Sirwan says:

    What is the link to the list of all the Diving into Php Days.

    these screencasts are excellent! thanks alot

  • Kayla says:

    Another great PHP tutorial. I’ve known OOP concepts for awhile related to Java and similar programming languages, but was always wary to get into it with PHP. Like you said, the books try to cram way to much in at once, and I think that was my problem. I didn’t realize how similar OOP could be between PHP and other languages.

    Can’t wait for more screencasts!

  • Julian says:

    Can’t wait to drive into OOP and harness it’s full potential – Great screencasts Jeff!

  • Daniel says:

    Awsome tuts!

    Can you maybe explain how to make a multi-language website, using friendly URLs, like used in CakePHP and other PHP MVC frameworks.


  • Brad Edwards says:

    Awesome series! Keep up the great work.


  • Rob says:

    Why did you say “it’s snot”?

  • James says:

    Brilliant! Thanks Jeff =) Well explained

    Frm England

  • Another excellent video tutorial, Jeff. As many people have said the work you put into creating these for us is greatly appreciated. I love your teaching style and continue to follow all of your screencasts.

    Great work, thanks again!

  • Tsalagi says:

    Jeff thanks so much for this series. It’s been a great beginning for me. I have a question but not sure if it’s appropriate here but it’s related somewhat. If I studied PHP, mysql, and Javascript for 5 hours a day how long should it take me to become fluent enough to market myself? I’m trying to get a benchmark to see if I’m picking this up quick enough. Sorry if it’s not the appropriate place and thanks for any responses.

  • Soso says:

    where is the next videos :)

  • Monit says:

    Hey Jeff,

    Awesome stuff, I was so scared of OOP before now I am not, I tried learning it many times but really was not going in my head, you explained it really well and simple way.

    Thanks and carry on the good work.

    You Rock

  • HeatON says:

    Jeffrey =]