PHP for Swift Developers
Transfer your Swift 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.
Swift and PHP side by side
The same program in Swift and in PHP, from the lessons of this course.
Modules and first run
Swift compiles a program with an entry point and imports modules that expose declarations. PHP executes a script and loads files with require_once. PHP files begin with an opening tag; __DIR__ anchors dependency paths. The course uses CLI modules rather than…
Swift1print("hello CLI")PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
Swift && and || short-circuit Boolean operands, and ?: selects a value. PHP offers similar syntax with broader truth conversion, plus lower-precedence and/or operators. Preserve parentheses and exact bounds so a superficially similar expression keeps its…
Swift1let n = 102if n >= 0 && n <= 10 { print("in") } else { print("out") }PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
Swift Array is a dense value collection; appending and removing change its count and positions. PHP arrays are ordered maps, and unset can leave gaps among numeric keys. Use array_values when an API or JSON output requires a dense list.
Swift1var values = [2, 3]2values.append(4)3print(values.count)PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
Swift signatures declare static types and optionals, with tuples available for multiple related results. PHP parameter and return declarations enforce runtime call boundaries. Scalar argument strictness follows the PHP caller’s strict_types setting, and array…
Swift1func twice(_ n: Int) -> Int { n * 2 }2print(twice(4))PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Swift throwing functions use throws, try and do/catch, with defer handling scope cleanup. PHP uses throw, typed catch and finally. Validate before mutation and translate expected contract failures deliberately instead of catching every programming error as a…
Swift1enum Problem: Error { case invalid }2func parse() throws -> Int { throw Problem.invalid }3do { _ = try parse() } catch { print("caught") }PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
Swift structs are value types and classes are reference types, with stored properties initialized according to type rules. PHP objects are reference-like identifiers and typed properties without defaults may be uninitialized. Choose an explicit representation…
Swift1struct Item { var n: Int }2let a = Item(n: 2)3let b = Item(n: 5)4print(a.n + b.n)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 Swift Developers for?
For people who already write Swift and want to learn PHP. Each lesson starts from Swift 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 Swift basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for Swift Developers have?
PHP for Swift Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for Swift Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for Swift Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.