PHP for TypeScript Developers
Transfer your TypeScript experience to PHP 8.3: values, control flow, arrays, functions, exceptions and object design. Build a multi-file time ledger with validated parsing and deterministic reports.
TypeScript and PHP side by side
The same program in TypeScript and in PHP, from the lessons of this course.
Modules and first run
TypeScript is checked and compiled before Node executes JavaScript; PHP runs its declarations directly. PHP require_once loads files without ES module namespaces. This course uses PHP 8.3 CLI, not browser APIs, and PHP scalar types are runtime contracts…
TypeScript1export {};2const message: string = "hello CLI"; console.log(message);PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
TypeScript uses JavaScript conditional and operand-returning &&/|| behavior, with control-flow narrowing at compile time. PHP &&/|| produce booleans. An equivalent-looking expression can therefore have a different result type as well as different truthiness…
TypeScript1export {};2const n: number=4; console.log(n>3?"high":"low");PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
TypeScript number[] still has JavaScript sparse-array behavior: delete leaves a hole while length stays three. PHP unset preserves keys but count counts entries. Static array syntax is not a promise of dense storage; noUncheckedIndexedAccess can make…
TypeScript1export {};2const a: number[]=[10,20,30]; delete a[1]; console.log(Object.keys(a).join(",")+":"+a.length);PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
TypeScript parameter and return annotations are checked before execution and erased. PHP declarations check runtime calls and returns. Passing an unchecked external value into compiled TypeScript still needs validation; neither a TS assertion nor a PHP array…
TypeScript1export {};2function surround(s:string):string{return "("+s+")";}console.log(surround("note"));PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Under strict TypeScript, caught values are unknown and need narrowing because JavaScript can throw any value. PHP catch selects Throwable types at runtime. Neither static narrowing nor a broad catch is a reason to suppress unexpected programming failures.
TypeScript1export {};2try{throw new Error("bad");}catch(e:unknown){if(e instanceof Error)console.log("caught:"+e.message);}finally{console.log("done");}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
TypeScript strictPropertyInitialization checks property initialization statically, with escape hatches such as definite-assignment assertions. PHP typed properties enforce initialized reads at runtime. A TypeScript ! marker does not create a runtime value…
TypeScript1export {};2class Flag{enabled:boolean=false;}console.log(new Flag().enabled?"on":"off");PHP1<?php2declare(strict_types=1);3class Flag {public bool $enabled=false;} $f=new Flag(); echo $f->enabled?"on\n":"off\n";
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsValues and output
7 lessonsControl flow
5 lessonsCollections
6 lessonsFunctions and modules
6 lessonsErrors and boundaries
4 lessonsObjects and state
4 lessonsObject contracts
6 lessonsSharing and identity
4 lessonsTime ledger project
4 lessonsFinal challenges
2 lessonsFrequently asked questions
Who is PHP for TypeScript Developers for?
For people who already write TypeScript and want to learn PHP. Each lesson starts from TypeScript you know and shows how PHP does the same thing, so you skip the beginner basics.
Do I need to know PHP already?
No. The course starts with your first PHP program. You need TypeScript basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for TypeScript Developers have?
PHP for TypeScript Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for TypeScript Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for TypeScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.