Data Types
Scalar types
Integer
Whole numbers without decimal points:
$count = 42;
$negative = -10;
$zero = 0;
Float
Numbers with decimal points:
$price = 19.99;
$pi = 3.14159;
$negative = -5.5;
String
Text values. Zymba supports three string delimiter styles:
$single = 'Hello'; // Single quotes — no interpolation
$double = "World"; // Double quotes — supports $variable interpolation
$multiline = `Line 1
Line 2
Line 3`; // Backtick strings — multiline, supports interpolation
Backtick strings are commonly used for SQL queries and multiline text:
$sql = `SELECT name, price
FROM items
WHERE status = 1
ORDER BY name`;
Boolean
$isActive = true;
$isDisabled = false;
Null
Represents the absence of a value:
$empty = null;
Complex types
Arrays
Ordered collections of values with optional string keys:
// Indexed array
$numbers = [1, 2, 3, 4, 5];
// Associative array (object-like)
$person = [name: "John", age: 30];
// Empty array
$empty = [];
Objects
Objects created with new object() or from a class:
$person = new object() {
name = "John";
age = 30;
};
Type checking
The is operator
$num = 42;
$str = "hello";
$arr = [1, 2, 3];
if ($num is numeric) { } // true for int and float
if ($str is string) { } // true
if ($arr is object) { } // true — arrays are objects in Zymba
Available type checks:
| Check | Description |
|---|---|
is numeric | Integer or float |
is int | Integer only |
is float | Float only |
is string | String type |
is bool | Boolean type |
is object | Array or object |
is null | Null value |
is function | Function or closure |
The typeof operator
Returns the type name as a string:
echo typeof 42; // "int"
echo typeof 3.14; // "float"
echo typeof "hello"; // "string"
echo typeof [1, 2]; // "object"
echo typeof null; // "null"
echo typeof function() {}; // "function"
The exists and empty operators
Check whether a variable or key exists, or whether a value is empty:
$name = "John";
if (exists $name) { } // true — variable is defined and not null
if (empty $name) { } // false — non-empty string
$blank = "";
if (empty $blank) { } // true — empty string is empty
The count operator
Returns the character count of a string or the element count of an array:
$str = "hello";
echo count $str; // 5
$arr = [1, 2, 3];
echo count $arr; // 3
Type casting
Explicitly convert between types:
$num = 42;
$floatNum = (float) $num; // 42.0
$strNum = (string) $num; // "42"
$price = "19.99";
$priceFloat = (float) $price; // 19.99
Available casts:
| Cast | Description |
|---|---|
(int) | Convert to integer (truncates decimals) |
(float) | Convert to float |
(string) | Convert to string |
(bool) | Convert to boolean |
You can also use unary + to coerce a value to a number:
$amount = +"42.50"; // 42.5 (float)
Truthiness rules
Values that are considered falsy in Zymba:
false0(integer zero)0.0(float zero)""(empty string)"0"(the string "0")null
Everything else is truthy, including empty arrays []:
if ([]) {
echo "empty array is truthy"; // This DOES execute
}
if (0) {
// This block does NOT execute — 0 is falsy
}
if ("0") {
// This block does NOT execute — "0" is falsy
}
"0" is falsy in Zymba. Check explicitly when you need to distinguish between null, "", and "0".