PHP for C# Developers
Transfer your C# 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.
C# and PHP side by side
The same program in C# and in PHP, from the lessons of this course.
Modules and first run
C# compiles an assembly with an entry point; PHP executes a script beginning with <?php and loads modules using require_once. C# using directives import namespace names, not PHP-style source files. This course uses ordinary PHP CLI rather than ASP.NET or a…
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7 8 static void Main() {9 Console.WriteLine("hello CLI");10 }11}PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
C# and PHP have ternary expressions and short-circuit boolean operators. C# enforces boolean operands for these conditions, whereas PHP accepts conversions. PHP additionally has low-precedence and/or spellings; use explicit grouping when porting a combined…
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7 8 static void Main() {9 int n=4;Console.WriteLine(n>3?"high":"low");10 }11}PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
C# arrays have fixed length and List<T>.RemoveAt shifts following positions. PHP unset preserves remaining numeric keys because its array is an ordered map. Use array_values when the PHP return contract requires a dense list.
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7 8 static void Main() {9 var a=new List<int>{10,20,30};a.RemoveAt(1);Console.WriteLine("0,1:"+a.Count);10 }11}PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
C# methods ordinarily belong to types, and local functions have lexical scope. PHP supports named free functions in modules as well as methods. PHP declared parameter and return types are checked at runtime; strict scalar argument behavior depends on the…
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7static string Surround(string s){return "("+s+")";}8 static void Main() {9 Console.WriteLine(Surround("note"));10 }11}PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
C# and PHP support typed catches and finally without Java-style checked exceptions. PHP Error and Exception both implement Throwable; C# exception hierarchies use System.Exception. Validate before mutation and catch expected contract failures instead of…
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7 8 static void Main() {9 try{throw new InvalidOperationException("bad");}catch(InvalidOperationException){Console.Write("caught");}finally{Console.WriteLine(":done");}10 }11}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
C# instance fields receive default values, including false for bool. PHP typed properties must be initialized before reads and do not automatically receive a type-specific default. C# auto-properties can wrap storage; a PHP public property is not an arbitrary…
C#1#nullable enable2using System;3using System.Collections.Generic;4using System.Linq;5 6class Program {7class Flag{public bool Enabled {get;set;}}8 static void Main() {9 Console.WriteLine(new Flag().Enabled?"on":"off");10 }11}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 C# Developers for?
For people who already write C# and want to learn PHP. Each lesson starts from C# 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 C# basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for C# Developers have?
PHP for C# Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for C# Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for C# Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.