PHPDoc

기본형태

@param 데이터타입 변수명 설명

@return 데이터타입 변수명 설명

@var 데이터타입 변수명 설명

@throws 에러타입 설명

사용예제

  1. 숫자키 배열: int[], array<int>

    [1,2,3]

  2. 문자키 배열: array<string, int>, array<string, Clazz>

    ['a' => 1, 'b' => 2]

  3. 각 키마다 형이 다를 경우의 배열 or 객체형태로표현하는 배열 : array{id: int, name: string}

    • @param array{0: string, 1: string, foo: stdClass, 28: false} $array

      // $array = ["hello", "world", "foo" => new stdClass, 28 => false];

    • @param array{0: string, 1: string, foo: stdClass, 28: false} $array

      // ['a','b','foo'=>new stdClass,28=>false]

    • @param array{0: int, 1: int} $array1

    • @param array{int, int} $array2

      [10,20]

  4. 옵셔널

    @param array{optional?: string, bar: int} $array

    //['optionalValue' => 'string','bar' => 42]

    // ['bar' => 42]

  1. 값이 없을때

    @return void

  2. 복수형태일때

    @return string | array

  1. 형태가 정해지지않았을때

    @return mixed


참조

https://tech-blog.rakus.co.jp/entry/20210326/php

http://blog.a-way-out.net/blog/2021/03/10/phpdoc-types/

https://prograshi.com/blog/param-return-in-php-docs/

https://zonuexe.github.io/phpDocumentor2-ja/references/phpdoc/index.html

Jul 14, 2023 Views 84