Slide 1

Slide 1 text

RFC起点で 数値らしい 文字列 を学ぶ 2024/09/25 PHP勉強会 LT

Slide 2

Slide 2 text

About Me ● Hiroki Inoue ● Software Engineer ● Engineering Manager 2

Slide 3

Slide 3 text

アジェンダ PHP RFC: Saner numeric strings[1] から学んだ話をします。 3 1. https://wiki.php.net/rfc/saner-numeric-strings

Slide 4

Slide 4 text

概要 文字列と数値にまつわる カテゴリ と ふるまい の話をします。 ● numeric string(数値文字列) ● leading-numeric string(先行数値文字列) ● non-numeric string(非数値文字列) 4

Slide 5

Slide 5 text

数値文字列 まとめるとこうなんだけど… 5 https://www.php.net/manual/en/language.types.numeric-strings.php

Slide 6

Slide 6 text

数値文字列 まとめるとこうなんだけど… 6 https://www.php.net/manual/en/language.types.numeric-strings.php RFCにはサンプルケースや背景情報が書かれてあり 理解を深めるのに役立ちました

Slide 7

Slide 7 text

文字列と“数値らしい”文字列 7 No 値 カテゴリ is_string is_numeric 1 “123” numeric string true true 2 “1.23e2” numeric string true true 3 “ 123” numeric string true true 4 “123 ” leading-numeric string true true 5 “123abc” leading-numeric string true false 6 “abc” non-numeric string true false

Slide 8

Slide 8 text

PHPのバージョンによる挙動の違い[1] 8 1. https://3v4l.org/Htv9K No 値 カテゴリ 8系 7系以前 1 “123” numeric string true true 2 “1.23e2” numeric string true true 3 “ 123” numeric string true true 4 “123 ” leading-numeric string true false 5 “123abc” leading-numeric string false false 6 “abc” non-numeric string false false

Slide 9

Slide 9 text

補足[1] “A fourth way PHP might deal with numeric strings is when using an integer string for an array index. An integer string is stricter than a numeric string as it has the following additional constraints: ● It doesn't accept leading whitespace ● It doesn't accept leading zeros (0)” “Another aspect which should be noted is that arithmetic/bitwise operators will...” 9 1. https://wiki.php.net/rfc/saner-numeric-strings#technical_background

Slide 10

Slide 10 text

理解しておきたいこと これらが使われる 文脈 と ふるまい 10

Slide 11

Slide 11 text

文脈とふるまいの例 11 ● 明示的な型変換 ● 引数 ● 文字列のオフセット ● 算術演算子 ● インクリメント/デクリメント ● ビット演算 ● 緩やかな比較

Slide 12

Slide 12 text

明示的な型変換 12 https://3v4l.org/gSTrE

Slide 13

Slide 13 text

引数 13 https://3v4l.org/eXW0s

Slide 14

Slide 14 text

文字列のオフセット 14 https://3v4l.org/3WKD6

Slide 15

Slide 15 text

算術演算子 15 https://3v4l.org/cBvnt

Slide 16

Slide 16 text

インクリメント/デクリメント 16 https://3v4l.org/I3FU3

Slide 17

Slide 17 text

ビット演算 17 https://3v4l.org/W8IJ1

Slide 18

Slide 18 text

緩やかな比較 18 https://3v4l.org/3sEnP

Slide 19

Slide 19 text

ご清聴ありがとうございました 19