Menu
CoddyTech
Course

Go for PHP Developers

Transfer your PHP experience to Go: typed values, control flow, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.

PHP and Go side by side

The same program in PHP and in Go, from the lessons of this course.

  1. Files and the first run

    PHP include and require evaluate files, while namespaces organize names separately. Go files in one directory form a package and compile together; imports do not execute arbitrary included source text. Each file lists its own imports, and the runner uses one…

    PHP
    1<?php2echo "ready\n";
    Go
    1package main2import ("fmt")3
    4func main(){fmt.Println("Go", 3)}
  2. If and scoped names

    PHP has ternary and null-coalescing expressions; Go has neither syntax. Use an if statement and a separate presence check. A zero, false or empty value can be meaningful, so choose the default based on the actual absence contract rather than PHP truthiness…

    PHP
    1<?php2$ready = true;3echo $ready ? 0 : 5, "\n";
    Go
    1package main2import ("fmt")3
    4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}
  3. Arrays are values

    PHP arrays are ordered maps supporting integer and string keys. Go distinguishes arrays, slices and maps. A Go array has a fixed length in its type; a slice is a variable-length view over backing storage. Do not transfer PHP array key behavior or iteration…

    PHP
    1<?php2$items = [4, 8];3echo array_push($items, 12), "\n";4echo $items[2], "\n";
    Go
    1package main2import ("fmt")3
    4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}
  4. Typed function contracts

    PHP functions can receive dynamically typed values, optionally constrained by declarations and coercion settings. Go signatures are statically checked and arguments are passed by value. Passing a pointer or slice still permits access to shared data, but no…

    PHP
    1<?php2function addItem($items) { $items[] = 9; }3$items = [1];4addItem($items);5echo count($items), "\n";
    Go
    1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}
  5. Struct values

    PHP classes use new and constructors, with object variables referring to shared instances. Go structs are values and assignment copies their fields. Use pointers when an API intentionally shares identity or mutable state. Go New-style functions are…

    PHP
    1<?php2class Parcel { public $label; }3$p = new Parcel();4$p->label = 'sample';5echo $p->label, "\n";
    Go
    1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}
  6. Errors are returned values

    PHP exceptions and Throwable use try/catch/finally. Go ordinary failures are error return values that callers check explicitly. Panic/recover is not the routine replacement for a parsing exception. Validate before mutation and preserve state when a business…

    PHP
    1<?php2function nonnegative(int $value):int {3 if($value<0)throw new InvalidArgumentException("negative");4 return $value;5}6try { echo nonnegative(-2),"\n"; }7catch(InvalidArgumentException $error) { echo "invalid\n"; }
    Go
    1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for PHP developers

Learn Go from another language

Frequently asked questions

Who is Go for PHP Developers for?

For people who already write PHP and want to learn Go. Each lesson starts from PHP you know and shows how Go does the same thing, so you skip the beginner basics.

Do I need to know Go already?

No. The course starts with your first Go program. You need PHP basics: variables, conditions, loops, functions and collections.

How many lessons does Go for PHP Developers have?

Go for PHP Developers contains 48 interactive lessons you can complete at your own pace.

What does Go for PHP Developers cover?

The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.

Is Go for PHP 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 Go for PHP Developers for free

Get started