Learning PHP sans bad habits

I’ve received some fatalistic responses to my last installment related to what I see as problems with PHP teachings. In particular, I fear we teach people to write applications in ways that are reckless to the fact that these individuals likely read no more than 1-2 PHP books and move on to start writing their application.

Now I’ll present some solutions I propose to the challenges of teaching PHP without encouraging bad habits from the beginning.

Chapter 1: Intro to PHP syntax using the commnd-line
Chapter 2: Make your first dynamic web page using our small framework (hello world)
The framework handles: data escaping input and output, proper sql injection protection, and data/presentation separation. The student needn’t understand all of this yet, but will be explained.
Chapter 3: Variables & Arrays
Chapter 4: Conditionals, Loops & Functions
Chapter 5: Classes
Chapter 6: Sending/Receiving data on the web.
Chapter 7: How to create additional pages in the framework
Chapter 8: Creating forms
Chapter 9: Dissect the framework input/output, presentation and database aspects
Chapter 10: Show how failing to do these things is insecure
Chapter 11: Create additional views/flow using OO framework
Chapter 12: Create a simple application with 3-4 views

This describes the mostly the PHP aspects of a book. This book could easily use SQLite and save the MySQL for another book where it can be properly introduced. It could also include some MySQL education to increase its marketability. The framework itself sounds like a big undertaking, but in fact it can be kept extremely simple as governed by the examples put forth herein. In addition, the frameworks simplicity will allow it to be dissected later in the book for the education of the reader. Finally, when someone finishes the book (or the worst risk with current books if they don’t finish it, they’ll still have the right ideas and not go willy-nilly writing an application using $_GET and $_POST without thinking twice.

[tags]teaching, learning, php[/tags]

4 thoughts on “Learning PHP sans bad habits

  1. Pingback: Ben Ramsey

  2. Hi, David. This is an interesting approach, but I think it’s a solution to a slightly different problem than teaching someone PHP. Instead, it’s a solution to teaching someone the basics of building a web app and you just happen to use PHP to teach those concepts. A perfectly worthwhile and desirable goal, but different.

    One of the most frequent concerns I hear from students and readers when I teach PHP and write about it is that they often feel they’re being cheated from the “real” language knowledge when a solution I advocate involves using a PEAR module or add-on library. I think this worry is misguided, but it is nevertheless common. Folks often want to learn “PHP”, not a library or framework that sits on top of it.

    So, part of the challenge is the meta-education that gets people comfortable with learning a particular toolset *plus* the language, not just the language. Doing this right involves making the concepts clear enough so that the learning is as transferrable as possible from one toolset to another — learning how and why to filter input and escape output in one framework should make it possible for the student to do the same thing, easily and quickly, with a new framework or toolset. We change jobs, change projects, do lots of things that require us to adapt to new conventions and libraries.

    The other potential issue with this approach is that some brittleness is hidden under the bucket of the framework you plan to create and its necessary simplicity. It is tough to strike the right balance between doing everything that one considers the minimum necessary to ensure proper conventions and practices (such as data escaping input and output, proper sql injection protection, and data/presentation separation) while simultaneously keeping the framework bits simple *and* making it extremely clear to students which things they’re doing are part of core PHP and which are conventions and add ons that this curriculum happens to use. At a certain point, it may just be more straightforward to pick a popular framework and use that. It’s probably not going to be that much more complicated than anything homegrown and offers students the advantage of some knowledge that’s directly transferrable to their job or hobby projects.

    All of these issues are not PHP-specific, but are, I think, more of an issue in PHP than with other languages since the community often prefers roll-your-own solutions rather than using existing code and that there is no clear winner for popular tasks that aren’t part of the core — tfor example, there’s no obvious framework that’s in the same position of dominance as Rails is for Ruby. So striking the right balance in teaching between “here’s *a* way to do some things that you’re definitely going to need but aren’t part of PHP out of the box” and “here’s *the* way to do those things” is tricky.

    Best of Luck!

  3. I like this approach – only after getting to know MVC / Proper OO Model I found myself comfortable in switching to ASP.Net for a few projects, and to know my way around the Java projects (Spring/Hibernate) I manage.

    Knowing this higher level of abstraction – it doesn’t really matter if you use PHP/Ruby/Java/C# – it’s all the same then :)

  4. Pingback: david | rasch — Management, Software, and Technology » don’t eat paste (learning PHP part iii)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>