CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

Concatenation Is Not a Parser Error

| Comments

CSI: PHP isn’t big on the perp walk, but if your crime is (1) public and (2) licensed with an Attribution-NonCommercial-ShareAlike Creative Commons license, then you kinda perp walked yourself.

1
2
3
4
5
6
7
8
9
<?php

// What will this print out in php5?
$earth = 'World';
$string1 = "Hello " .
$string2 = $earth . '!';
$string = $string1 . $string2;

echo $string;

The author posits the output, Hello World!World!, is a possible parser error or internal assignment nonsense. What Hello World!World! actually represents is PHP string handling and variable assignment 101.

I will concede that determining the output of $string is something of a light brain teaser. However, if you’re confused by concatenation and variable assignment to the point that you write a blog post about it and present it as a parser error, I can only hope and pray you’re trolling.

Exit question, “If a plane crashes on the border of Canada and the United States, where do you bury the survivors?”

Comments