StandardNerd
StandardNerd

Reputation: 4183

PHP Type Annotation for functions?

In PHP it's common to type annotate variables like this:

  /**
   * @var boolean
   */
  protected $isLoaded;

But what about the return types in functions? Does PHP Type Annotation support the return type of a function?

If so, how can I annotate the return type of the function in class diagram

-getName(): String

?

I would expect something like:

  /**
   * @return String
   */
  private function getName() {}

But it's ignored.

Upvotes: 0

Views: 939

Answers (1)

colburton
colburton

Reputation: 4715

That would just be:

/**
 * @return string
 */
private function getName(): string {}

The annotation is optional at this point.

Upvotes: 1

Related Questions