Y-KANOH
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    PHPerのための「PHPと型定義を語り合う」 PHP TechCafe ================================================= # PHPer's NEWS ::: info **[PHPでもAIの波に乗る - openai clientを使ってみる](https://qiita.com/niisan-tokyo/items/d98e3c480e07c4e678a5)** 世界的ですもんね 乗るしかない、このビッグウェーブに ::: ::: info **[Laravelのwithとjoinの違いについて](https://qiita.com/ryocha12/items/8bf538b89739b903e437)** なにかと話題になるN+1問題 ::: ::: info **[GitHub Code Searchがは一般的に利用可能に](https://github.blog/2023-05-08-github-code-search-is-generally-available/)** ロジック実装時にCopilotを利用して開発しつつ、リファレンスとなるコードが欲しいときは、GitHub Code Searchで検索など開発スピード爆上がりしそう。 ::: ::: info **[PHP重鎮の廣川類氏によるコラム「PHPの最新状況:PHP 8.3の開発が本格化」](https://column.prime-strategy.co.jp/archives/column_5672)** ::: ::: info **[GitHubのリポジトリを仮想地図としてマッピングしているサイト](https://anvaka.github.io/map-of-github/#5.5/-41.685/-26.949)** ::: ::: info **[生成系人工知能(生成AI)についての学長からのメッセージ(武蔵野美術大学)](https://www.musabi.ac.jp/news/20230511_03_01/)** ::: ::: info **[Researcher hijacks popular Packagist PHP packages to get a job 研究者が仕事を得るために人気のある Packagist PHP パッケージを乗っ取る](https://www.bleepingcomputer.com/news/security/researcher-hijacks-popular-packagist-php-packages-to-get-a-job/)** ::: ::: info **[PHPの将来性と需要って大丈夫?](https://axxis.co.jp/magazine/54431)** 扱っている言語の需要や動向は気になるのでたまにこの手の記事を見ています。 WEBのサーバサイドはやはりPHP強いなといったところ。 (私がPHP書いてないやん?Javaそんなに書いてないから許して…) ::: ::: info **[Xdebug at 21](https://derickrethans.nl/xdebug-21.html)** Xdebugの開発は最低でも月25時間必要な模様です。 PHP開発においてほぼ確実に利用するツールなだけに何か協力できないかという気持ちになりました。 ::: ::: info **[Packagist.org maintainer account takeover](https://blog.packagist.com/packagist-org-maintainer-account-takeover/)** 他のプラットフォームで漏洩したパスワードを共有パスワードとして利用していたことが原因だった模様。 二要素認証を推奨しているので、Packagistに限らず、二要素認証が設定できるツールでは積極的に設定していきたい。 ::: ::: info **[How and When to Use PHP’s Pure Intersection Types](https://doganoo.medium.com/how-and-when-to-use-phps-pure-intersection-types-2189aa8359c1)** メリットや注意点が記載されており、交差型の利用イメージが沸くかと思いました。 今回のテーマにあった内容化と思います。 ::: ::: info **[Observability vs monitoring](https://laravel-news.com/observability-vs-monitoring)** 詳細は追って追記します。 ::: ::: info **[【PHP8.3】unserializeのエラーハンドリングがいいかんじになるよ](https://qiita.com/rana_kualu/items/fc1a359b85118b4b7a76)** 現在の「unserialize()」関数は、エラーが発生した場合に警告や例外をスローするだけで、具体的なエラー情報は提供されません。しかし、この提案では、復元操作中に発生したエラーに関する詳細な情報を提供し、開発者が問題を特定しやすくすることを目指しています。 ::: ::: info **[レガシーコードとどう付き合うか 発売](https://amzn.asia/d/8gOP75y)*** ::: # 特集:PHPと型 ## PHPと型 ### 静的型付け言語 変数や関数の引数、戻り値などに対して、あらかじめ指定された型以外を使用できなくする言語のこと。 「型推論」によって明示的に型を指定しなくても文脈などからコンパイラが予測してくれるものもある。 ### 動的型付け言語 ←PHPはこっち 変数や関数の引数、戻り値の型を実行時の値によって決定することができる言語のこと。 ただし、PHPのように型が指定できる動的型付け言語もある。 ## PHPの単一の式が持つ型 * null * bool * int * float * string * array * object * callable * resource ## PHPの型システムで扱える型 ### 基本型 * 組み込みの型 * ヌル(null) * スカラー型: * 論理値(bool) * 整数(int) * 浮動小数点数(float) * 文字列(string) * 配列(array) * オブジェクト(object) * リソース(resource) * never * void * クラス内での関係を示す相対型: self, parent, static * リテラル型 * false * true * ユーザー定義型 (一般的に、クラス型とも呼びます) * インターフェイス * クラス * 列挙型(Enum) * callable ### 複合型 * 交差型 * union型 ### 型のエイリアス * mixed: `object|resource|array|string|float|int|bool|null`のエイリアス * iterable: `Traversable|array`のエイリアス ## PHPで取り入れられた型表現 戻り値への型指定 ```php function hoge():string { return "hoge"; } ``` 引数への型指定 ```php function fuga(int $a, int $b) { return $a + $b; } ``` **PHP 8.2.0:** DNF 型が追加。 **PHP 8.2.0:** リテラル型 true が追加。 **PHP 8.2.0:** null と false 型が、独立した型として使えるように。 **PHP 8.1.0:** 交差型が追加。 **PHP 8.1.0:** 戻り値を void とした関数からリファレンスを返すことが非推奨に。 **PHP 8.1.0:** 戻り値にのみ指定できる型として、 never 型が追加。 **PHP 8.0.0:** mixed 型が追加。 **PHP 8.0.0:** 戻り値にのみ指定できる型として、 static 型が追加。 **PHP 8.0.0:** union 型が追加。 **PHP 7.2.0:** object 型が追加。 **PHP 7.1.0:** iterable 型が追加。 **PHP 7.1.0:** void 型が追加。 **PHP 7.1.0:** nullable な型が追加。 * 作った関数が誤った意図で使われることを防ぐことができる([参考](https://toku1.jp/programming-php-typedeclarations/)) * 受け取った値のチェックを型宣言に任せられる * 「`is_array()`で配列か毎回チェック」ということがなくなる ## PHPDocの役割 参考:[PHPDocリファレンス](https://zonuexe.github.io/phpDocumentor2-ja/references/phpdoc/index.html) PHPのソースコードに記載するコメント。 実装者がコードの内容を確認できるだけでなく、ルールに従って記載することでIDEや静的解析などのツールで活用することができる。 ### メリット * 静的解析に使える * コメントなので実際の挙動に影響を与えない * バグにならないことが保証されている * リファクタリングでとっつきやすい * 参考:[リーダブルなPHPDocを目指して](https://speakerdeck.com/rakus_dev/20210707-readablelt-nishihara) ### デメリット * 所詮はコメント * 間違っていても動く → 間違ったコメントである可能性もある * メンテしないと逆効果 ```php= /** * 手元のPhpStormで検知されたもの * @param string hoge * @deprecated hoge * @internal hoge * @return hoge * @throws hoge * @version hoge * @uses hoge * @see hoge * * 手元のPhpStormで検知されなかったもの * @api * @author hoge * @category hoge * @copyright hoge * @example hoge * @filesource hoge * @xglobal hoge * @license hoge * @link hoge * @method hoge * @package hoge * @property hoge * @since hoge * @source hoge * @todo hoge * @example hoge * @internal hoge * @inheritdoc hoge * @link hoge */ ``` ## 言語使用の型表現とPHPDocのどちらを使うべき? * 新規プロダクトでは? * 既存のプロダクトでは? * どういうところに型があると嬉しいのか? * 既存システムに型宣言を書くのは難しい? * まずはPHPDocから始める([参考](https://speakerdeck.com/penguin045/phpergakorekara-xing-toofu-kihe-isiteikutameni?slide=33)) * 動作を制限しないがIDEの支援を受けられる * テストが必要 ## 事前にいただいた質問コーナー * never型(noreturn型)のうまいつかいどころ、(私を含む一部の過激派による)ジェネリクス待望論などがあれば聞きたいです。 * テストコードは静的解析の対象に入れるべきか否か * 型運用のための設計についてお聞きしたいです。(DTOクラスってPHPでも使うものなのか等) ## 参考資料 * [php.net: 型](https://www.php.net/manual/ja/language.types.php) * [php.net: 型宣言](https://www.php.net/manual/ja/language.types.declarations.php) * [PHPで型宣言してますか?](https://tech-blog.rakus.co.jp/entry/20220323/php) * [型を使いこなすためのPHPDocの書き方](https://tech-blog.rakus.co.jp/entry/20210326/php) * [PHPerのための「PHPDoc相談会」PHPTechCafe](https://hackmd.io/oPjJcVmoRGSBtq0wlD4h9w) * [PHPerのための「PHPDoc相談会」【PHP TechCafe イベントレポート】](https://tech-blog.rakus.co.jp/entry/20230517/PHPDoc)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully