PHP Data Types, Type Juggling vs Strict Typing & Variable Storage
Explore all 8+ PHP types (int, float, string, bool, null, array, object, resource), zval internal storage, type juggling pitfalls, and strict_types=1.
- Scalar:
int,float,string,bool. - Compound:
array,object,callable,iterable. - Special:
null,resource(external handle like file/stream).
1. PHP Data Types
- Scalar:
int,float,string,bool. - Compound:
array,object,callable,iterable. - Special:
null,resource(external handle like file/stream).
2. Internal Storage (`zval`) & Type Juggling
Internally, every PHP variable is stored in a `zval` container tracking its type, value, and reference count. By default, PHP uses weak typing (type juggling)—coercing "42" to 42 in arithmetic. Adding declare(strict_types=1); at the top of a file enforces strict type checks on function calls and returns!
3. Value vs. Reference Semantics
Primitives and arrays use Copy-on-Write (CoW) value semantics; objects pass handles by object identifier (mutating an object's properties inside a function affects the caller's object).
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)