PHP for Go Developers
Transfer your Go 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.
Go and PHP side by side
The same program in Go and in PHP, from the lessons of this course.
Modules and first run
Go builds packages and runs main in package main; imports connect compiled package declarations. PHP executes a script and loads files with require_once at runtime. PHP files need an opening tag, and __DIR__ anchors dependencies. The course uses CLI modules…
Go1package main2import ("fmt")3 4func main(){5fmt.Println("hello CLI")6}PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
Go if requires a Boolean condition and braces; it has no ternary conditional operator. PHP offers ?: and converts values in conditions. Its and/or spellings also differ in precedence from &&/||. Preserve the original grouping and exact inclusive or exclusive…
Go1package main2import ("fmt")3 4func main(){5n:=10; if n>=0 && n<=10 {fmt.Println("in")} else {fmt.Println("out")}6}PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
Go slices describe a dense view into backing storage; removing an element often shifts a suffix and shortens the slice. PHP arrays are ordered maps, so unset can leave numeric gaps. Reindex with array_values when the public API or JSON requires a dense list.
Go1package main2import ("fmt"; "strings")3 4func main(){5a:=[]string{"a","b","c"}; a=append(a[:1],a[2:]...); fmt.Println(strings.Join(a,","))6}PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
Go function signatures are checked statically and may declare several results. PHP parameter and return declarations are runtime contracts, generally with one returned value. Scalar argument strictness follows the PHP caller’s strict_types setting, and array…
Go1package main2import ("fmt")3func twice(n int) int {return n*2}4func main(){5fmt.Println(twice(4))6}PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
Go commonly returns an error alongside successful results; panic and recover are a different mechanism from routine validation. PHP uses exceptions and catch for failed contracts. Validate before mutation and translate expected rejection explicitly so the…
Go1package main2import ("fmt")3func setPositive(value *int,next int)error{if next<0{return fmt.Errorf("negative")};*value=next;return nil}4 5func main(){6value:=4;err:=setPositive(&value,-1);if err!=nil{fmt.Printf("rejected:%d\n",value)}7}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
Go structs declare fields with zero values and can be initialized through composite literals; methods attach behavior separately. PHP classes combine properties and methods, and typed properties without defaults may be uninitialized. Establish valid state…
Go1package main2import ("fmt")3type Item struct {N int}4func main(){5a:=Item{N:2}; b:=Item{N:5}; fmt.Println(a.N+b.N)6}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 Go Developers for?
For people who already write Go and want to learn PHP. Each lesson starts from Go 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 Go basics: variables, conditions, loops, functions and collections.
How many lessons does PHP for Go Developers have?
PHP for Go Developers contains 48 interactive lessons you can complete at your own pace.
What does PHP for Go Developers cover?
The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.
Is PHP for Go Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.