Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP: null, default null, nullable and void
Search
DQNEO
July 25, 2018
Programming
0
370
PHP: null, default null, nullable and void
PHPのnull, = null, nullable, voidについておさらいしてみよう
DQNEO
July 25, 2018
Tweet
Share
More Decks by DQNEO
See All by DQNEO
英和辞書付きGo言語仕様書 / Word Wise Go Spec
dqneo
1
500
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
6
1.6k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.2k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
dqneo
9
4.9k
How to write a self hosted Go compiler from scratch (Gophercon 2020)
dqneo
3
1.6k
もっと気軽にOSSに Pull Requestを出そう!/ Let's make a PR to OSS more easily
dqneo
6
8.3k
Goコンパイラをゼロから作ってセルフホスト達成するまで / How I wrote a self hosted Go compiler from scratch
dqneo
15
14k
コンパイラをつくってみよう / How to make a compiler
dqneo
9
11k
コンパイラ作りの魅力を語る / Making compilers is fun
dqneo
10
8.4k
Other Decks in Programming
See All in Programming
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.4k
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
140
Dissecting and Reconstructing Ruby Syntactic Structures
ydah
1
750
Chrome Extension Techniques from Hell
moznion
1
160
設計の本質:コード、システム、そして組織へ / The Essence of Design: To Code, Systems, and Organizations
nrslib
4
630
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
エンジニアが挑む、限界までの越境
nealle
1
240
プロフェッショナルとしての成長「問題の深掘り」が導く真のスキルアップ / issue-analysis-and-skill-up
minodriven
7
1.5k
Building a macOS screen saver with Kotlin (Android Makers 2025)
zsmb
1
160
Thank you <💅>, What's the Next?
ahoxa
1
490
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.1k
Optimizing JRuby 10
headius
0
390
Featured
See All Featured
For a Future-Friendly Web
brad_frost
176
9.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Six Lessons from altMBA
skipperchong
27
3.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Making Projects Easy
brettharned
116
6.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Raft: Consensus for Rubyists
vanstee
137
6.9k
A Tale of Four Properties
chriscoyier
158
23k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Typedesign – Prime Four
hannesfritz
41
2.6k
Done Done
chrislema
183
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Transcript
!%2/&0 Ͳ͖ΎͶ͓ BU.FSDBSJ *OD QIQTUVEZ OVMM OVMM OVMMBCMF WPJE ʹ͍͓ͭͯ͞Β͍͠Α͏
OVMMͱԿ͔
σϑΥϧτOVMMͱ
OVMMBCMFͱ
WPJEͱ
ࠓ ʮͳ͍ʯͱԿ͔ʹ͍ͭͯ ߟ͑ͯΈΑ͏
OVMMͱԿ͔ • null型のnullという値 (null型にはnullという1種類の値しかな い)
͜ΕOVMM $x = null var_dump($x);
͜ΕOVMM function f() { } var_dump(f()); 関数が何も返さなかった場合、戻り値はnullとなる
σϑΥϧτOVMMͱ function f(int $a, int $b = null) { return
[$a, $b]; } f(1); // [1, null] 引数を渡さなかったときのデフォルト値
ͱࢥ͏͡Όͳ͍Ͱ͔͢ʁ ͦΕ͚ͩ͡Όͳ͍ΜͰ͢
function f(int $a = null, int $b) { } 引数を渡さなかったときのデフォルト値?
function f(int $a = null, int $b) { return [$a,
$b]; } f(1,2); => [1,2] f(1); => Fatal error f(); => Fatal error 引数を渡さなかったときのデフォルト値? 第1引数を渡さないってそれ無理では?
function f(int $a = null, int $b =null, in t
$c) { } f(null, null, 1); => [null, null, 1] もはや「デフォルト値」じゃなくない? だって引数渡してるもん
ͦ͏ɺ ඞਢҾΑΓࠨʹ͋ΔOVMMશͯ ʮσϑΥϧτʯ ͷׂΛࣦ͍ͬͯΔ
OVMM ͏ͻͱͭผͷҙຯ͕͋Δɻ ʮOVMMΛड͚ͱΓՄೳʯ
ʮOVMMΛड͚ͱΓՄೳʯ ͭ·ΓOVMMBCMF
function f(int $a = null, int $b) { } function
f(?int $a, int $b) { } この場合は= nullじゃなくてnullableを使おう 可読性向上!
ʮσϑΥϧτҾʯͷ߹ OVMMBCMFએݴͰ͖Δ function f(int $a, int $b = null) {
} function f(int $a, ?int $b = null) { }
ͪͳΈʹ ʮσϑΥϧτOVMMʯͷ ׂΛ࣋ͨͳ͍ function f(int $a, ?int $b) { }
f(1); => Fatal error
ΓͷOVMMBCMFએݴɺ ͳͩ͠ͱΤϥʔ function f() ?int { return; } f(); =>
Fatal error
ΓͷOVMMBCMFએݴɺ ໌ࣔతʹOVMMΛฦ͢ඞཁ͋Γ function f() ?int { return null; } f();
=> null
WPJEͱ
1)1͔Βೖͬͨ৽ߏจ function f() :void { } function f() :void {
return; } 関数が値を返さないことを宣言できる
ݺͼग़͠ଆࢹͩͱOVMM function f() :void { } var_dump(f()); // null void型関数を実行するとnullが得られる
͔͠͠OVMMΛSFUVSO͢ΔͱΤϥʔ function f() :void { return null; } var_dump(f()); //Fatal
error: A void function must not return a value 「returnの右に式を書いてはいけない」くらいの意味
w OVMM w σϑΥϧτOVMM w OVMMBCMF w WPJE Ҏ্ɺ ʹ͍͓ͭͯ͞Β͍͠·ͨ͠
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ NN