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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
DQNEO
July 25, 2018
Programming
410
0
Share
PHP: null, default null, nullable and void
PHPのnull, = null, nullable, voidについておさらいしてみよう
DQNEO
July 25, 2018
More Decks by DQNEO
See All by DQNEO
英和辞書付きGo言語仕様書 / Word Wise Go Spec
dqneo
1
580
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
6
1.8k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.3k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
dqneo
9
5.3k
How to write a self hosted Go compiler from scratch (Gophercon 2020)
dqneo
3
1.7k
もっと気軽にOSSに Pull Requestを出そう!/ Let's make a PR to OSS more easily
dqneo
6
8.5k
Goコンパイラをゼロから作ってセルフホスト達成するまで / How I wrote a self hosted Go compiler from scratch
dqneo
15
15k
コンパイラをつくってみよう / How to make a compiler
dqneo
9
12k
コンパイラ作りの魅力を語る / Making compilers is fun
dqneo
10
8.7k
Other Decks in Programming
See All in Programming
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
160
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
380
The free-lunch guide to idea circularity
hollycummins
0
390
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
110
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
AI活用のコスパを最大化する方法
ochtum
0
360
Feature Toggle は捨てやすく使おう
gennei
0
390
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
260
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Claude Codeログ基盤の構築
giginet
PRO
7
3.8k
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
610
Designing Powerful Visuals for Engaging Learning
tmiket
1
320
A designer walks into a library…
pauljervisheath
210
24k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
250
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
How STYLIGHT went responsive
nonsquared
100
6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
What's in a price? How to price your products and services
michaelherold
247
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Thoughts on Productivity
jonyablonski
75
5.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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