PHP for Rust Developers
Transfer your Rust 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.
Rust and PHP side by side
The same program in Rust and in PHP, from the lessons of this course.
Modules and first run
Rust compiles crates and starts a binary at main, with modules organizing declarations at compile time. PHP executes an entry script and loads files with require_once. PHP needs an opening tag and uses __DIR__ for dependency paths. The course builds CLI…
Rust1 2fn main(){3println!("hello CLI");4}PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
Rust if is an expression and &&/|| short-circuit Boolean operands. PHP uses ?: for conditional values and permits truth conversion. PHP and/or have lower precedence than &&/||, so preserve grouping, the chosen result type and every inclusive or exclusive…
Rust1fn main() {2let n=10; println!("{}",if n>=0 && n<=10 {"in"} else {"out"});3}PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
Rust Vec.remove shifts later values to keep indexes dense and transfers ownership of the removed item. PHP unset removes a key without renumbering the rest. Reindex with array_values when an API or JSON output requires a dense list.
Rust1fn main() {2let mut values=vec!["a","b","c"]; values.remove(1); println!("{}",values.join(","));3}PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
Rust signatures declare types and borrow relationships, with Option and Result making common alternatives explicit. PHP declarations enforce runtime boundaries around parameters and returns. Scalar strictness follows the PHP caller, and array does not specify…
Rust1fn twice(n:i32)->i32 {n*2}2fn main() {3println!("{}",twice(4));4}PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Rust commonly represents recoverable failure with Result and propagates it using ?, rather than exceptions. PHP throws Throwable objects and handles them with catch and finally. Translate expected rejection deliberately and validate before mutation so failed…
Rust1fn main() {2let result:Result<i32,&str>=Err("bad"); match result {Ok(n)=>println!("{}",n),Err(_)=>println!("caught")};3}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
Rust structs declare fields, and impl blocks provide associated functions and methods; initialization and borrowing are statically checked. PHP classes combine properties and methods, with typed properties possibly uninitialized at runtime. Establish valid…
Rust1struct Item{n:i32}2impl Item{fn new(n:i32)->Self{Self{n}}}3fn main() {4let a=Item::new(2); let b=Item::new(5); println!("{}",a.n+b.n);5}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 Rust Developers for?
For people who already write Rust and want to learn PHP. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for Rust Developers have?
PHP for Rust Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for Rust Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for Rust Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.