Menu
CoddyTech
Course

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.

  1. 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.

    Python
    1print("hello CLI")
    PHP
    1<?php2declare(strict_types=1);3echo "hello CLI\n";
  2. 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.

    Python
    1n = 42print("high" if n > 3 else "low")
    PHP
    1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";
  3. 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.

    Python
    1a = [10, 20, 30]2del a[1]3print(",".join(str(i) for i in range(len(a))))
    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

    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.

    Python
    1def surround(s: str) -> str:2    return "(" + s + ")"3print(surround("note"))
    PHP
    1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";
  5. 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.

    Python
    1try:2    raise RuntimeError("bad")3except RuntimeError:4    print("caught", end="")5finally:6    print(":done")
    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

    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.

    Python
    1class Flag:2    def __init__(self):3        self.enabled = False4f = Flag()5print("on" if f.enabled else "off")
    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 Python developers

Learn PHP from another language

Frequently 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.

Coddy programming languages illustration

Start PHP for Python Developers for free

Get started