PHP: Building Cool Stuff but So Many Pieces Pieces in the Carpet Awaiting Their Next Victim.
What it's like being introduced to PHP.
Design week 2 recap will have to wait. Today I want to post about grappling with PHP for the first time.
Some amount of time ago, Derrick gave us a tiny little code and instructions to split our html files <?php include”thisfile.php”?>
. It was explained that we could use the same file in multiple places, which is handy for something like a header or footer.
Then last week we were handed a shiny package full of PHP legos with a gorgeous brick house on the box and some instructions inside. (Just in case it isn’t clear, this is a metaphor) It had special pieces like $
variables, arrays = [1,2,3,]
and functions (functionname) {instructions}.
You open the box by displaying the mystical phrase “<?php”
. The special pieces interlock or concatenate together with periods.
Items in a list are separated by commas, but the list is grouped together by brackets, instructions are delineated by curly brackets, and commands are often ended with semicolons. It’s a cluttered mess and all the PHP blocks don’t resemble anything until they are gobbled up by the server and served out as beautiful creations of HTML code. When it’s time to switch to another coding plaything, you carefully tuck away the PHP code with the tiny “?>”.
It all seemed so easy at first.
$variables are items that are declared.
Arrays are lists. So simple!
Functions are instructions. I know how to read instructions!
Except, PHP is that professor/teacher you always hated. You know the one. The one that grades your paper with an F but doesn’t explain why and tells you some vague answer about how to correct your paper. They have to leave their visiting hours early to run the strip bar they co-own with their brother. (No one else had that professor?)
PHP syntax rules are seemingly RANDOM AND WEIRD. A little missed comma, period, or semicolon can break the whole page. The error messages often point you in the direction of the solution, like a road map that only states “the destination is West” or “somewhere on Sunset BLVD.” Arrays are especially devious. If we go with the direction metaphor, arrays spray painted over the freeway exit sign and laugh while you drive miles in the wrong direction. If you prefer the lego metaphor, arrays are the shockingly sharp and painful block that finds its way under your foot at night.
Despite how ugly and frustrating it is to play with, PHP is weirdly fun. HTML is human-readable and simple (so far), CSS can steal hours of my day with its visual delight, but PHP can DO THINGS. It can cut down the total amount I have to code or make sections of my code sync with minimal effort. It can use functions, so the server generates fun gimmicks like having each section rotate through this list of background colors without me having to assign a class in CSS and keep track of it by hand. It can fill out paragraphs of text and pull up the relevant data for me. Even if it’s obtuse and difficult to write, it makes things easier. PHP can build the instructions for the lego house and generate the blocks it’s made with.
So for a little over a week, I have had fun playing with PHP lego blocks and trying to build little php-lego-brick-houses. Every time I think I have built a wall, I realize there were no legos inside that box. I am actually holding the base elements of plastic, and I am only part of the way through forming each lego. Understanding how to use and speak the language of PHP is hard, and I naively keep thinking I finally understand, only to realize I don’t. This whole process is slower than I would prefer, and part of learning is realizing I know less than I think I do. It’s fun and frustrating all the same time.