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

fwdays 157 views 29 slides Aug 19, 2024
Slide 1
Slide 1 of 29
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29

About This Presentation

Talk on data types and how PHP works with them at the core level with use cases for more efficient utilization.


Slide Content

Денис Курасов 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 1 6 bytes 64 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.17549435 E-38 3.4028235 E +38 8 bytes Actual Memory 12 bytes 16 bytes 64 bit 32 bit

Float - IEEE754 V = (-1) s * M * 2 E 536870912000000 1111010000100100000000000000000000000000000000000 01010111111101000010010000000000 1.907348*2 48 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 bytes 64 bit 16 bytes 64 bit IS_FALSE

Array

Array Data Layout

INVALID_IDX NULL 1 1 1 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 1 key2 DJBX33A hash fn 6385400192 6385400192 | -4 -4 1 1 key3 DJBX33A hash fn 6385400193 6385400193 | -4 -4 INVALID_IDX 2 -1 -2 -4 1 2 3 -3 Key Val

INVALID_IDX NULL 1 1 1 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