9 Responses to “OOP Registration-Login Part I: Secure & Verify”


  • Great Blog! The download files on this article isn’t working. Can you please fix it?

  • 2 questions –
    1. You have mentioned in a few of your articles that using conditional loops is not advisable. Instead use object calls. Why is that so?
    2. What is the recommended approach – using heredoc or creating another html file but with php extension and then using it in the include tag?

  • Hi Amitesh,

    1. The main reason that I avoid conditional loops is that they can be very hard to update, re-use and debug.(They can tangle your code like a ball of twine!) With recursive functions, you have conditionals but not loops, even though they function like loops in repeating an operation. They are easier to untangle and debug. As for using objects instead of conditional loops; I was probably referring to having a set of conditions that are requested in the same PHP file. Avoid long and unwieldy conditionals that lead to functions and more functions in the same PHP file. Rather, favor composition, and use class-objects for different requests.

    2. I recommend getting rid of all “free range chickens” in HTML code. That is, encapsulate your HTML (esp HTML5!) in PHP classes. Then, you can use all of the advantages of an OOP class with your HTML code, including implementations of interfaces and inheritance.

    Kindest regards,
    Bill

  • Thanks Amitesh,

    Whoops! My bad…I had a typo in the file name. You can now download it.

    Happy PHP OOP Computing,
    Bill

  • Bill – THANK YOU SO MUCH to both of my questions, especially the conditional loops one. It makes perfect sense. Last question – I believe in having php files for all my code (including html) but include the html code in a separate file which is than called by my index.php file. However, in your code you used Heredoc. Is there any best practices around using my way vs. yours (as in using Heredoc is more secure etc.)?

  • Great Bill! The download works now.

    I just got onto OOP PHP and loving every bit of it (never used an OOP language in my life) and your blog has been superb in this journey.

    There are a couple of other places in the blog where the download isn’t working. When I have time later, I will send you those articles so you can fix the broken links.

  • Hi Amitesh,

    Developers treat HTML in all different kinds of manner. Some just slap on “.php” to the end of an HTML file name, some drop in PHP code (variables or functions) where they need it and some treat HTML as a one-time-UI. In this particular post you can see how the encapsulated HTML in a class is able to implement the IUI interface. The value of the constant in that interface can now be used in the class of which HTML is a part. The constant, BLETCHLY is encoded, and so all you can see in the source code (Figure 1) is the encoded name; not the actual name of the table. By being part of a class, your HTML has all of advantages of an OOP class. You don’t have to encapsulate external CSS or JS files, but calling them from an encapsulated class allows them to be “encapsulated-in-use”. So, I agree that encapsulating HTML in a class (heredoc is the easiest way) is a best practice for OOP PHP.

    Kindest regards,
    Bill

  • This code is bad. If I don’t add password, error doesn’t show up.

  • Coder,

    You are absolutely right! Thank you for pointing that out. The focus of this post is to see how to use OOP to create a registration form, and I did not include error handling. That needs to be done, and I’m working on it now. In fact, this may be a good opportunity to use a lambda function.

    I’ll race you. If you get it done first, you win! If I do, I win. We both have to follow good OOP practices and use a lambda function (anonymous function.) As soon as you’re finish, put your post here in the comments, and I’ll do the same.

    Kindest regards,
    Bill

Leave a Reply