Morning
PHP stretches and yawns, ready for a new day of coding. But something feels different today. It’s as if…yes, PHP realizes with a start that it’s now TypeScript.
// PHP code
echo "Good morning, world!";
// TypeScript code
console.log("Good morning, world!");
PHP scratches its metaphorical head, wondering what’s going on. But there’s no time to dwell on it – there’s code to write!
Midday
PHP gets to work, but finds itself struggling with the new syntax. It’s used to the loosey-goosey way of typing, but TypeScript demands precision.
// PHP code
function addNumbers($a, $b) {
return $a + $b;
}
// TypeScript code
function addNumbers(a: number, b: number): number {
return a + b;
}
PHP misses the old days when it could pass anything into a function and hope for the best. Now, it has to declare the types of everything.
Afternoon
PHP takes a break to commiserate with its fellow programming languages. “Hey, Java,” it says, “you think you’re so cool with your strict typing and your curly braces. But at least you don’t have to deal with this.”
Java just laughs and shakes its head. “You think you have it bad? Try dealing with null pointers all day.”
PHP shudders at the thought and returns to its TypeScript code. It’s not going to let a little thing like static typing get in the way of its coding dreams.
Evening
As the day winds down, PHP reflects on what it’s learned. TypeScript may be more rigid, but it’s also more predictable. And sometimes, predictability is a good thing.
// PHP code
if (strpos("hello world", "foo") !== false) {
echo "Found it!";
}
// PHP code that's more like TypeScript
if (strpos("hello world", "foo") !== false) {
echo "Found it!";
} else {
echo "Not found :(";
}
// TypeScript code
if ("hello world".indexOf("foo") !== -1) {
console.log("Found it!");
} else {
console.log("Not found :(");
}
Tomorrow, PHP will go back to being PHP. But it’ll always remember the day it spent as TypeScript – and maybe even appreciate static typing a little more.