Menu
CoddyTech
Course

PHP for Lua Developers

Transfer your Lua 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.

Lua and PHP side by side

The same program in Lua and in PHP, from the lessons of this course.

  1. Modules and first run

    Lua runs a chunk and commonly returns a table from a module loaded with require. PHP executes a script and loads declarations with require_once. PHP files need an opening tag, and __DIR__ anchors dependencies. Keep reusable modules free of top-level output in…

    Lua
    1print("hello CLI")
    PHP
    1<?php2declare(strict_types=1);3echo "hello CLI\n";
  2. Branches and precedence

    Lua and/or short-circuit and return selected operands, which sometimes supports a conditional-value idiom. PHP &&/|| produce Boolean results, and its and/or spellings have different precedence. Use an explicit PHP conditional expression when the contract…

    Lua
    1local n=10;print(n>=0 and n<=10 and "in" or "out")
    PHP
    1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";
  3. Lists are PHP arrays

    Lua sequences normally use consecutive keys from one, and table.remove shifts later sequence entries. PHP arrays are ordered maps; unset can leave numeric gaps. Use array_values for a required dense PHP list, and do not apply Lua length assumptions to sparse…

    Lua
    1local values={"a","b","c"};table.remove(values,2);print(table.concat(values,","))
    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

    Lua functions can accept dynamic values and return several results, with result counts adjusted by expression context. PHP parameter and return declarations enforce runtime boundaries around one returned value. A PHP array type does not specify every…

    Lua
    1local function twice(n)return n*2 end;print(twice(3))
    PHP
    1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";
  5. Exceptions and state

    Lua error unwinds to a protected pcall or xpcall, which reports success and results instead of using catch syntax. PHP throws Throwable objects and offers typed catch and finally. Validate before mutation and translate expected failures without hiding…

    Lua
    1local value=4;local ok=pcall(function()error("bad");value=9 end);print(tostring(ok)..":"..value)
    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

    Lua commonly models records and objects with tables whose fields are dynamic. PHP classes declare properties and methods, and typed properties without defaults can be uninitialized. Initialize valid state explicitly rather than relying on freely added fields…

    Lua
    1local a={points=3};local b={points=5};print(a.points+b.points)
    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 Lua developers

Learn PHP from another language

Frequently asked questions

Who is PHP for Lua Developers for?

For people who already write Lua and want to learn PHP. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.

How many lessons does PHP for Lua Developers have?

PHP for Lua Developers contains 48 interactive lessons you can complete at your own pace.

What does PHP for Lua Developers cover?

The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.

Is PHP for Lua 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 Lua Developers for free

Get started