PHP for Python Developers
Transfer your Python 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.
Python and PHP side by side
The same program in Python and in PHP, from the lessons of this course.
Modules and first run
Python executes a script without an opening tag. PHP needs <?php, semicolons and explicit file loading. Neither course launcher is a web request.
Python1print("hello CLI")PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
Python puts the selected true expression before if. PHP puts the condition first and uses ? and :. Python and/or return operands, whereas PHP && and || yield booleans.
Python1n = 42print("high" if n > 3 else "low")PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
Deleting a Python list element shifts later positions. PHP unset deletes a map entry and preserves its remaining keys. Calling array_values is an explicit reindexing step, not a cosmetic one.
Python1a = [10, 20, 30]2del a[1]3print(",".join(str(i) for i in range(len(a))))PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
Python annotations ordinarily do not enforce argument or return types at runtime. PHP declared types participate in runtime checking. Neither language annotation automatically verifies business rules or array element types.
Python1def surround(s: str) -> str:2 return "(" + s + ")"3print(surround("note"))PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Python except corresponds to PHP catch, and both support finally. PHP Exception and Error implement Throwable; catching Exception alone does not catch every Error such as TypeError. Choose the boundary deliberately.
Python1try:2 raise RuntimeError("bad")3except RuntimeError:4 print("caught", end="")5finally:6 print(":done")PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
Python commonly creates instance attributes inside __init__. PHP should declare properties, with runtime types and visibility. A Python type hint alone neither creates nor initializes an instance attribute.
Python1class Flag:2 def __init__(self):3 self.enabled = False4f = Flag()5print("on" if f.enabled else "off")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 Python Developers for?
For people who already write Python and want to learn PHP. Each lesson starts from Python 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 Python basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for Python Developers have?
PHP for Python Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for Python Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for Python Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.