Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHP関西勉強会LT資料.pdf
Search
nishimura syota
June 25, 2025
26
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP関西勉強会LT資料.pdf
nishimura syota
June 25, 2025
More Decks by nishimura syota
See All by nishimura syota
PHP関西勉強会のLT資料
syota
0
8
Featured
See All Featured
Abbi's Birthday
coloredviolet
4
10k
WENDY [Excerpt]
tessaabrams
14
40k
We Are The Robots
honzajavorek
0
400
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
640
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Speed Design
sergeychernyshev
33
2.2k
How STYLIGHT went responsive
nonsquared
100
6.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Transcript
3分で始める 「意図が伝わる」コード設計入門 1
自己紹介 かけ(@kake4723) PHPエンジニア歴:2年6ヶ月 所属:株式会社TechBowl 趣味 ラジオ聴くこと 野球 2
カンファレンスで発表する内容を 少しだけご紹介! 実際の発表では、これらをより詳しく解説します 3
こんな経験ありませんか? よくある困りごと 「このプロパティ変更されてる!」 「どこで値が変わったの?」 「意図しない変更を防ぎたい」 解決策があります! PHP 8の新機能で 3分で体感できる改善を 明日から実践できる形でご紹介
4
本日のテーマ PHP 8で実現する「意図が伝わる」コード設計 3つのポイントで即効性のある改善を 1. 型付けで安全性向上 2. readonlyで意図しない変更を防止 3. 実践例で即活用
5
型付けの威力 Before function calc($price, $rate) { return $price * $rate;
} After function calculateTax( int $price, float $rate ): float { return $price * $rate; } 効果 実行前にエラー発見 IDEが自動補完 意図が明確 6 型を書くだけで安心感UP!
意図しない変更の問題 プロパティが予期せず変更される... class User { public $id; public $email; public
function __construct($id, $email) { $this->id = $id; $this->email = $email; } } $user = new User(1, "
[email protected]
"); $user->id = 999; // 意図しない変更! 7
readonly でスッキリ解決! 意図しない変更を防止 class User { public readonly int $id;
public readonly string $email; public function __construct( int $id, string $email ) { $this->id = $id; $this->email = $email; } } $user = new User(1, "
[email protected]
"); // $user->id = 999; // エラー!変更不可 メリット 意図が明確 変更を防止 型安全性 8 意図しない変更をブロック!
よくある問題コード class Order { public $id; public $total; public function
__construct($id, $total) { $this->id = $id; $this->total = $total; } } $order = new Order(1, 1000); $order->total = -500; // 負の値! $order->id = null; // 不正な値! 問題点 型なし・変更可能・不正な値の代入 → バグの温床 9
型とreadonly で安全設計! class Order { public readonly int $id; public
readonly int $total; public string $status; public function __construct(int $id, int $total) { $this->id = $id; $this->total = $total; $this->status = 'pending'; } } // $order->id = 999; // エラー!変更不可 // $order->total = -500; // エラー!変更不可 改善効果:不正な変更を防止・意図が明確・型安全性向上 10
明日から始める2ステップ 基本の型付け function getUser(int $id): ?User { // 型を明記して意図を明確に }
readonly プロパティで安全性向上 class User { public readonly int $id; public readonly string $email; // 意図しない変更を防止 } 11
型とreadonly で、 ミスを事前に見つけることができます。 明日から「意図が伝わる」PHPを 一緒に書きましょう! ご清聴ありがとうございました! 12