Data Types
In PHP, variables can store all sorts of data — strings, numbers, booleans, arrays, and so on. Each type behaves a little differently, but PHP handles most of this automatically. That’s part of what makes it so flexible.
You can always check what kind of data a variable holds with var_dump().
$x = 5;
var_dump($x);
That’ll tell you both the type and the value.
A string is just text — something wrapped in quotes. Both single and double quotes work:
$name = "Pretty Links";
$tagline = 'Track and manage your URLs easily.';
var_dump($name);
var_dump($tagline);
The difference between single and double quotes, as we’ve seen before, is that double quotes can interpret variables inside them.
An integer is a whole number — no decimals, just straight values like 42 or -300.
$activeMembers = 5985;
var_dump($activeMembers);
A float (or “double”) is a number that includes decimals, like when you’re working with prices or measurements.
$conversionRate = 10.365;
var_dump($conversionRate);
A boolean is either true or false. They’re often used for simple logic, like checking if a MemberPress subscription is active or not:
$isActive = true;
var_dump($isActive);
An array is a way to store multiple values under one variable — like a list of supported plugins in the CaseProof ecosystem:
$plugins = ["MemberPress", "Pretty Links", "ThirstyAffiliates"];
var_dump($plugins);
Then there are objects, which come from classes. Think of a class as a “blueprint” — and each object as something built from that blueprint. If you had a class representing a plugin, each instance might represent a specific one with its own properties.
class Plugin {
public $name;
public $type;
public function __construct($name, $type) {
$this->name = $name;
$this->type = $type;
}
public function describe() {
return "This is a {$this->type} plugin called {$this->name}.";
}
}
$mp = new Plugin("MemberPress", "membership");
var_dump($mp);
Don’t worry too much about objects yet — there’s a whole section on that later.
NULL is PHP’s way of saying “nothing here.” It’s a special data type that literally means the variable has no value.
$discount = null;
var_dump($discount);
If you create a variable but don’t assign anything, PHP automatically gives it NULL by default.
Now, PHP is smart enough to change a variable’s type based on what you assign to it:
$x = 5;
var_dump($x);
$x = "Five";
var_dump($x);
If you do want to manually change a variable’s type without changing its value, you can cast it:
$x = 5;
$x = (string) $x;
var_dump($x);
Finally, there’s resource, which isn’t a “real” data type in the usual sense — it represents a reference to something external, like a database connection or a file handle. You’ll see that in action when working with databases or API calls.