PHP
๐ What Are PHP Data Types?
PHP is a dynamically (loosely) typed language. This means you do not need to manually specify data types when declaring variables. PHP automatically detects and assigns the correct data type by evaluating the value assigned to the variable.
$sayi = 10; // Automatically detected as Integer
$metin = "Merhaba"; // Automatically detected as String
- Important Note: PHP has strong data types; it simply uses automatic type detection instead of requiring manual type definitions.
๐๏ธ Categories of PHP Data Types
PHP data types are categorized into three main structural groups:
- 1. Primary (Basic) Data Types: Boolean, Integer, Float/Double, String
- 2. Compound Data Types: Array, Object
- 3. Special Data Types: Resource, Null, Callable
1๏ธโฃ Primary (Basic) Data Types
๐น Boolean (Logical)
Represents truth values used primarily in conditional checks. It accepts only two values: true or false.
$aktif = true;
๐น Integer (Whole Numbers)
Non-decimal whole numbers that can be positive or negative. Supports binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16) notations.
$sayi = -8;
๐น Double / Float (Floating-Point Numbers)
Numbers containing decimal points or fractional parts.
$fiyat = 8.88;
๐น String (Textual Data)
Sequences of letters, numbers, and symbols enclosed within single (' ') or double (" ") quotation marks.
$isim = "Volkan Alakent";
2๏ธโฃ Compound Data Types
๐น Array
Collection type that stores multiple values within a single variable using zero-based indexing or associative keys.
$liste = ["Elma", "Armut", "Muz"];
๐น Object
Instances instantiated from class definitions in Object-Oriented Programming (OOP), holding properties and methods.
$nesne = new Araba();
3๏ธโฃ Special Data Types
๐น Resource
Special variables holding references to external system resources such as database connections, open files, cURL handles, FTP sockets, or image buffers.
$baglanti = mysqli_connect("localhost", "root", "", "veritabani");
๐น Null
Special data type representing an empty variable with no assigned value or explicitly reset to null.
$veri = null;
๐น Callable
References to functions, methods, or anonymous callbacks that can be invoked dynamically during script execution.
function selam() {
echo "Merhaba";
}
$fonk = "selam";
$fonk(); // Triggers callable function
-
๐ Brief Summary
- PHP automatically detects data types dynamically without requiring explicit declarations.
- Data types are divided into Primary (Basic), Compound, and Special types.
- Understanding data types helps write efficient, error-free PHP backend logic.
