Originally published on php2rust.dev — part of the PHP to Rust course. View this lesson on the original site.
This section summarizes Rust and PHP data types and composite structures; we’ll look at each of these in more detail throughout this chapter.
Key points
- Rust: Scalars (integers, floats, bools, chars), tuples, arrays, slices, strings, structs, and enums.
- PHP: Scalars (int, float, bool, string), arrays, objects, enums (8.1+).
- Rust: Strong static typing; arrays fixed-size; slices are views.
- PHP: Dynamic typing; arrays can be associative or indexed; objects for OOP.
- Rust:
String(owned) vs&str(slice); UTF-8 only. - PHP: Single
stringtype; typically UTF-8 when handling text.
Comparison
- Structs vs classes: Rust structs are data-only; PHP classes combine data and behaviour.
- Enums: Rust enums can hold data per variant; PHP backed enums map to scalars.
- Option/null: Rust uses
Option<T>; PHP usesnulland?T. - Collections: Rust has
Vec,HashMapin std; PHP has arrays and SPL types.
References
What's next
Next: Scalar types.
From PHP to Rust — Rust Syntax and Functions