Slide 1

Slide 1 text

New features in PHP8.4 Saki Takamachi

Slide 2

Slide 2 text

About me ● PHP8.4 RM ● PHP Foundation Core Developer ● specialty: ext/pdo, ext/bcmath ● Singer ● Have 4 year old son and 1 year old daughter

Slide 3

Slide 3 text

PHP 8.4 has been released!

Slide 4

Slide 4 text

About smaller new features and changes ● RoundingMode Enum ● PDO Firebird Transaction isolation level …etc There are quite a lot of them, so I will introduce the ones I was involved with.

Slide 5

Slide 5 text

RoundingMode Enum by Saki Takamachi, Tim Düsterhus

Slide 6

Slide 6 text

RoundingMode Enum ● PHP_ROUND_HALF_UP ● PHP_ROUND_HALF_DOWN ● PHP_ROUND_HALF_EVEN ● PHP_ROUND_HALF_ODD + 4 new modes 4 new modes by Jorg Sowa

Slide 7

Slide 7 text

RoundingMode Enum this is correct

Slide 8

Slide 8 text

RoundingMode Enum -5 is "UP" to -10 ?

Slide 9

Slide 9 text

RoundingMode Enum Added four new modes and now them using the correct wording. The words "UP" and "DOWN" are intentionally not used because they are easily confused with the previous mode names.

Slide 10

Slide 10 text

RoundingMode Enum union type. We assume the int type it will be abolished at some point, but the timing is completely undecided.

Slide 11

Slide 11 text

PDO Firebird Transaction isolation level by Saki Takamachi

Slide 12

Slide 12 text

PDO Firebird Transaction isolation level ● There was no way to set transaction isolation level ● Until now, it was always "Read committed"

Slide 13

Slide 13 text

PDO Firebird Transaction isolation level There are three levels of transaction isolation level.

Slide 14

Slide 14 text

About major new features ● Asymmetric visibility property ● Lazy object ● PDO driver specific sub-classes ● Property hooks ● BcMath\Number Class …etc

Slide 15

Slide 15 text

Asymmetric visibility property by Ilija Tovilo, Larry Garfield

Slide 16

Slide 16 text

Asymmetric visibility property Up to PHP 8.3, get and set visibility is always the same.

Slide 17

Slide 17 text

Asymmetric visibility property By using the Asymmetric visibility property, can write code like the one above.

Slide 18

Slide 18 text

Asymmetric visibility property I also often write like this: Up to PHP 8.3 often see code like this

Slide 19

Slide 19 text

Asymmetric visibility property Please ignore the red line :) From PHP 8.4, you can write like this!

Slide 20

Slide 20 text

Asymmetric visibility property private get, public set Set with weaker visibility than get are not allowed.

Slide 21

Slide 21 text

Lazy Object by Arnaud Le Blanc, Nicolas Grekas

Slide 22

Slide 22 text

Lazy Object There are two types of deferred object generation methods.

Slide 23

Slide 23 text

Lazy Object The return value of the callback is different. Ghost is void, proxy is object.

Slide 24

Slide 24 text

PDO driver specific sub-classes by Danack

Slide 25

Slide 25 text

PDO driver specific sub-classes ● pdo_dblib ● pdo_firebird ● pdo_mysql ● pdo_odbc ● pdo_pgsql ● pdo_sqlite ※ pdo_oci has been unbundled.

Slide 26

Slide 26 text

PDO driver specific sub-classes ● Pdo\Dblib ● Pdo\Firebird ● Pdo\Mysql ● Pdo\Odbc ● Pdo\Pgsql ● Pdo\Sqlite ※ pdo_oci has been unbundled. ※ Unbundled drivers can be subclassed as well.

Slide 27

Slide 27 text

Property hooks by Ilija Tovilo, Larry Garfield

Slide 28

Slide 28 text

Property hooks

Slide 29

Slide 29 text

Property hooks Validation typically protects against accepting invalid values.

Slide 30

Slide 30 text

Property hooks Please ignore the red line :) Validation can be done with property hooks

Slide 31

Slide 31 text

Property hooks fullName is a virtual property. There is no need to persist data, as a return value is always generated.

Slide 32

Slide 32 text

Property hooks Since it has become easier to use public properties, there will likely be more opportunities to specify properties in interfaces.

Slide 33

Slide 33 text

BcMath\Number Class by Saki Takamachi

Slide 34

Slide 34 text

Before talking about Class, let me talk about improving performance and adding functions :)

Slide 35

Slide 35 text

BCMath performance gain PHP 8.3 ● add: 3.0387s ● sub: 3.0248s ● mul: 5.7315s ● div: 25.762s Results of a certain benchmark (rough) Calculate numbers with a maximum of about 60 digits instead of unrealistically large values PHP 8.4 ● add: 1.4444s ● sub: 1.4745s ● mul: 2.0621s ● div: 2.9411s

Slide 36

Slide 36 text

BCMath Added functions ● bcround() ● bcfloor() ● bcceil() ● bcdivmod()

Slide 37

Slide 37 text

BCMath Added functions Division, which used to be executed twice, can now be executed once.

Slide 38

Slide 38 text

BcMath\Number Class BcMath\Number is a readonly class. That is, it is immutable.

Slide 39

Slide 39 text

BcMath\Number Class Since it is a Final class, inheritance is not possible. There was a very long discussion about whether or not to allow inheritance.

Slide 40

Slide 40 text

BcMath\Number Class Supports four arithmetic operations, pow, mod, and comparison operators. Also, this class is Stringable.

Slide 41

Slide 41 text

BcMath\Number Class The argument also accepts int. Be careful when passing a float, as an implicit cast to int is attempted, not to string.

Slide 42

Slide 42 text

BcMath\Number Class The scale will be set automatically.

Slide 43

Slide 43 text

BcMath\Number Class If the calculation is not divisible, what is the result....?

Slide 44

Slide 44 text

BcMath\Number Class For calculations with methods, you can explicitly specify the scale with an optional argument.

Slide 45

Slide 45 text

BcMath\Number Class If you do not explicitly specify the scale of the result, add up to 10 to "dividend Scale."

Slide 46

Slide 46 text

BcMath\Number Class If the calculation ends before adding 10 to scale, no more scale are added.

Slide 47

Slide 47 text

BcMath\Number Class GMP does not handle decimals, so it does not compete completely with BCMath, and each has its place.

Slide 48

Slide 48 text

Thank you for your attention! Enjoy betterCode() and have a nice day!