Денис Курасов
PHP CORE – ЧАСТИНА 1 – ТИПИ ЗМІННИХ
PHP
fwdays
About Myself
• Lead PHP developer at Growe
• Over 8 years of experience in backend development
• Passionate about computer science
• Experienced in embedded development, gained through
university projects, including creating a self-driving robot
• Football is in my heart
What is variable?
Types in core
Zval
Zend value
Integer
zend_long
Represents
int64_t
int32_t -2147483648
-9223372036854775808 8 bytes
4 bytes
Max
Min
2147483647
9223372036854775807
Memory
In C Actual Memory
12 bytes
16 bytes64 bit
32 bit
Integer - Integer In Memory
Integer - Integer Overflow
Float | Double | Real
double
4 bytes
Max
Min Memory
In C
1.7976931348623157E+308
2.2250738585072014E-308
float 1.17549435E-38 3.4028235E+38
8 bytes
Actual Memory
12 bytes
16 bytes
64 bit
32 bit
Float - IEEE754
V = (-1)s
* M * 2E
536870912000000 1111010000100100000000000000000000000000000000000
01010111111101000010010000000000
1.907348*248
M
E
Float - IEEE754 Float 32 bits
0.1640625
1.120393e-38
INF
NaN
Float - Round-off error
Float - Mistakes that are worth lives
25 Feb 1991
(0.000110011001100110011001)2
(0.099999964237213134765625)10
0.1 - 0.099999904632568359375 = 9.54 * 10-8
sec
9.54 * 10-8
* 10 * 60 * 60 * 100 = 0.34344 sec
Error after working 100 hours
Error
2000 * 0.34344 = 687 metres
(0.1)10 ≈
Float - Comparing Floats
Float - Dangerous operations with
Float
Boolean
IS_TRUE 1 byte
Actual Memory
Memory
In C (PHP Core)
1 byte
16 bytes64 bit
16 bytes64 bit
IS_FALSE
Array
Array Data Layout
INVALID_IDX NULL
0 1
1 1
0
INVALID_IDX 2
-1
-2
-4 1 2 3
-3
Key
Val
INVALID_IDX INVALID_IDX
INVALID_IDX NULL NULL NULL NULL
key1
DJBX33A hash
fn
6385400191
6385400191| -4
-1
0 1
key2
DJBX33A hash
fn
6385400192
6385400192 | -4
-4
1 1
key3
DJBX33A hash
fn
6385400193
6385400193 | -4
-4
0
INVALID_IDX 2
-1
-2
-4 1 2 3
-3
Key
Val
INVALID_IDX NULL
0 1
1 1
0
INVALID_IDX 2
-1
-2
-4 1 2 3
-3
Key
Val UNDEF
Array – Memory
SPL Fixed Array
String
PHP string in core
Define string in C
String - UTF-8, how?
String - Interned Strings
String - Concatenation
Questions?
Thank you for
watching

"PHP Core – Part 1 – Understanding Variables Types", Denys Kurasov