Menu
CoddyTech
Course

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.

  1. 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…

    JavaScript
    1console.log("hello CLI");
    PHP
    1<?php2declare(strict_types=1);3echo "hello CLI\n";
  2. 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…

    JavaScript
    1const n = 4; console.log(n > 3 ? "high" : "low");
    PHP
    1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";
  3. 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…

    JavaScript
    1const a = [10,20,30]; delete a[1]; console.log(Object.keys(a).join(",") + ":" + a.length);
    PHP
    1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";
  4. 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…

    JavaScript
    1function surround(s) {return "(" + s + ")";} console.log(surround("note"));
    PHP
    1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";
  5. 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…

    JavaScript
    1try {throw new Error("bad");} catch(e) {process.stdout.write("caught");} finally {console.log(":done");}
    PHP
    1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}
  6. 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…

    JavaScript
    1class Flag {enabled = false;} console.log(new Flag().enabled ? "on" : "off");
    PHP
    1<?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 questions

More courses for JavaScript developers

Learn PHP from another language

Frequently 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.

Coddy programming languages illustration

Start PHP for JavaScript Developers for free

Get started