LoginSignup
4
4

More than 5 years have passed since last update.

[PHP] タイプヒンティング

Last updated at Posted at 2014-09-29

なにか?

関数の引数の型を明示する

なぜ使う?

型が明示されてるので、変数がイメージしやすくなる。
結果、内部処理が読みやすくなる。
エラーを早めにキャッチできる

サンプルコード

TypeHinting.php
<?php

$data   = array();
$data[] = 'hoge';
$data[] = 'foo';

// この間50行くらい

// あ、$dataは配列なのか、と想定してコード読める
function typeHinting(array $data)
{
   ......
}

more

まだありがたみはわからないが、
継承元の関数の引数が明示されていたりするとわかりやすくなるのかも。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4