PHP for Java Developers
Transfer your Java 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.
Java and PHP side by side
The same program in Java and in PHP, from the lessons of this course.
Modules and first run
Java compiles classes and starts at a static main method. PHP executes an entry script and loads declarations with require_once. PHP files need an opening tag; __DIR__ anchors module paths. The PHP course uses CLI input rather than a servlet or web framework.
Java1import java.util.*;2 3class Main {4 5 public static void main(String[] args) throws Exception {6 System.out.println("hello CLI");7 }8}PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
Java and PHP share ternary syntax and short-circuit boolean &&/||. Java enforces boolean conditions statically; PHP can coerce other values. PHP and/or are additional lower-precedence operators, so prefer explicit parentheses when translating combined…
Java1import java.util.*;2 3class Main {4 5 public static void main(String[] args) throws Exception {6 int n=4;System.out.println(n>3?"high":"low");7 }8}PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
Java arrays have fixed length; ArrayList removal shifts positions and changes size. PHP unset preserves remaining numeric keys, because a PHP array is an ordered map. Explicit array_values reindexing is needed for a dense-list contract after deletion.
Java1import java.util.*;2 3class Main {4 5 public static void main(String[] args) throws Exception {6 List<Integer> a=new ArrayList<>(Arrays.asList(10,20,30));a.remove(1);System.out.println("0,1:"+a.size());7 }8}PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
Java methods belong to classes; this helper is static because main has no receiver. PHP also supports free functions in modules. Both languages can declare parameter and return types, but PHP enforces them at runtime and strict scalar behavior depends on the…
Java1import java.util.*;2 3class Main {4static String surround(String s){return "("+s+")";}5 public static void main(String[] args) throws Exception {6 System.out.println(surround("note"));7 }8}PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Java distinguishes checked and unchecked exceptions, requiring catch-or-declare for checked exceptions. PHP has no checked-exception declaration mechanism. Typed catch and finally exist in both; validate before mutation so expected rejection preserves state.
Java1import java.util.*;2 3class Main {4 5 public static void main(String[] args) throws Exception {6 try{throw new IllegalArgumentException("bad");}catch(IllegalArgumentException e){System.out.print("caught");}finally{System.out.println(":done");}7 }8}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
Java instance primitive fields receive default values such as false. An uninitialized PHP typed property does not receive the corresponding zero value and cannot be read. Explicit PHP initialization is required even when a nullable declaration might suggest…
Java1import java.util.*;2 3class Main {4static class Flag{boolean enabled;}5 public static void main(String[] args) throws Exception {6 System.out.println(new Flag().enabled?"on":"off");7 }8}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 Java Developers for?
For people who already write Java and want to learn PHP. Each lesson starts from Java 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 Java basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for Java Developers have?
PHP for Java Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for Java Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for Java Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.