Reading — step 1 of 5
Learn
~1 min readGetting Started
PHP is dynamically typed — variables don't declare their type:
$count = 5; // int
$name = "Alice"; // string
$active = true; // bool
$ratio = 1.5; // float
$nothing = null;
The type can change at runtime — $count = "hello" is legal. Use gettype($var) or var_dump($var) to inspect at runtime.
PHP has type juggling — automatic conversion in many contexts. "5" + 3 is 8 (string converted to int). "5" . 3 is "53" (int converted to string by the concat operator .). This is convenient until it isn't — modern PHP code uses strict type declarations on functions to prevent surprises.
Constants use define('MAX', 100) or the modern const MAX = 100;. Both are global; constants don't take the $ prefix.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…