PHP for JavaScript Developers
Transfer your JavaScript 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.
JavaScript and PHP side by side
The same program in JavaScript and in PHP, from the lessons of this course.
Modules and first run
JavaScript Node scripts run without a PHP opening tag. PHP uses <?php and explicit require_once paths. Node CommonJS require returns exported values; PHP require_once loads declarations without creating a module namespace. This course uses CLI scripts, not…
JavaScript1console.log("hello CLI");PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
The ternary syntax is familiar from JavaScript, but JavaScript && and || return operands whereas PHP && and || return booleans. PHP also has lower-precedence and/or operators; use parentheses and the intended operator instead of assuming all spellings behave…
JavaScript1const n = 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
JavaScript delete leaves an array hole and does not reduce length. PHP unset preserves remaining numeric keys, but count counts existing entries. JavaScript splice shifts elements; PHP array_values explicitly reindexes after removal. Similar displayed keys do…
JavaScript1const a = [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
JavaScript has no built-in parameter type declarations in this function. PHP scalar and return declarations participate in runtime checks, with strict_types controlling scalar argument coercion at the caller. An array annotation still does not validate…
JavaScript1function surround(s) {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
JavaScript permits throwing arbitrary values and has an untyped catch binding. PHP throws objects implementing Throwable and can select typed catch clauses. Do not catch all failures as business errors; distinguish expected rejection from programming mistakes…
JavaScript1try {throw new Error("bad");} catch(e) {process.stdout.write("caught");} 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
JavaScript public fields can be created dynamically and have no runtime scalar type declaration. PHP should declare typed properties explicitly; dynamic properties are deprecated for ordinary classes. A nullable PHP property still needs initialization before…
JavaScript1class Flag {enabled = 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 JavaScript Developers for?
For people who already write JavaScript and want to learn PHP. Each lesson starts from JavaScript 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 JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for JavaScript Developers have?
PHP for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for JavaScript Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for JavaScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.