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.
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…
Lua1print("hello CLI")PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";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…
Lua1local n=10;print(n>=0 and n<=10 and "in" or "out")PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";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…
Lua1local values={"a","b","c"};table.remove(values,2);print(table.concat(values,","))PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";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…
Lua1local function twice(n)return n*2 end;print(twice(3))PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";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…
Lua1local value=4;local ok=pcall(function()error("bad");value=9 end);print(tostring(ok)..":"..value)PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}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…
Lua1local a={points=3};local b={points=5};print(a.points+b.points)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 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.