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 translation units and starts at main; PHP executes a script and loads declarations with require_once. An opening PHP tag marks code, and __DIR__ anchors file paths. This course uses CLI programs and separate modules without a web framework.
C++1#include <iostream>2 3int main() {4 std::cout << "hello CLI\n";5}PHP1<?php2declare(strict_types=1);3echo "hello CLI\n";Branches and precedence
C++ && and || short-circuit, and its alternative and/or spellings have the same precedence as those operators. PHP and/or have lower precedence than && and ||. Preserve parentheses and boundary conditions instead of carrying operator spelling across unchanged.
C++1#include <iostream>2 3int main() {4 int score=7; std::cout << (score>=5 && score<10 ? "middle" : "other") << "\n";5}PHP1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";Lists are PHP arrays
C++ vector stores a dense sequence, and erase shifts later elements to close the gap. PHP arrays are ordered maps whose keys can remain sparse after unset. Apply array_values when the public contract requires consecutive list keys or JSON list output.
C++1#include <iostream>2#include <vector>3 4int main() {5 std::vector<int> values{10,20,30};values.erase(values.begin()+1);std::cout<<values.size()<<":"<<values[1]<<"\n";6}PHP1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";Functions and return types
C++ function signatures and overload resolution are checked at compilation, with conversions following static types. PHP parameter and return types are runtime contracts. Scalar argument strictness follows the PHP caller’s strict_types setting, and array does…
C++1#include <iostream>2int twice(int value){return value*2;}3 4int main() {5 std::cout<<twice(3)<<"\n";6}PHP1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";Exceptions and state
C++ throws exceptions and uses RAII destructors for cleanup during stack unwinding rather than a finally keyword. PHP provides catch and finally. In both, validate before mutation so a rejected operation leaves its invariant intact rather than requiring a…
C++1#include <iostream>2#include <stdexcept>3 4int main() {5 int value=4;try{if(value>0)throw std::invalid_argument("bad");value=9;}catch(const std::invalid_argument&){std::cout<<"caught:"<<value<<"\n";}6}PHP1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}Classes and typed properties
C++ classes and structs have fixed member types and explicit initialization rules; uninitialized scalar members can be unsafe to read. PHP typed properties likewise need initialization before access unless they have defaults. Construct independent instances…
C++1#include <iostream>2struct Score { int points=0; };3 4int main() {5 Score a{3};std::cout<<a.points<<"\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 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.