Skip to content

Commit

Permalink
Merge pull request php-fig#163 from ashnazg/iterable
Browse files Browse the repository at this point in the history
add iterable type
  • Loading branch information
ashnazg authored Oct 14, 2018
2 parents 5c3dcd6 + 2595420 commit 1b01816
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions proposed/phpdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ A Type has the following [ABNF][RFC5234] definition:
collection-type = class-name / "array"
class-name = ["\"] label *("\" label)
label = (ALPHA / %x7F-FF) *(ALPHA / DIGIT / %x7F-FF)
keyword = "array" / "bool" / "callable" / "false" / "float" / "int" / "mixed" / "null" / "object" /
keyword = "array" / "bool" / "callable" / "false" / "float" / "int" / "iterable" / "mixed" / "null" / "object" /
keyword = "resource" / "self" / "static" / "string" / "true" / "void" / "$this"

### Details
Expand Down Expand Up @@ -670,12 +670,14 @@ The following keywords are recognized by this PSR:

6. `array`: the element to which this type applies is an array of values.

7. `resource`: the element to which this type applies is a resource per the [definition of PHP][PHP_RESOURCE].
7. `iterable`: the element to which this type applies is an array or Traversable object per the [definition of PHP][PHP_ITERABLE].

8. `mixed`: the element to which this type applies can be of any type as specified here. It is not known at compile
8. `resource`: the element to which this type applies is a resource per the [definition of PHP][PHP_RESOURCE].

9. `mixed`: the element to which this type applies can be of any type as specified here. It is not known at compile
time which type will be used.

9. `void`: this type is commonly only used when defining the return type of a method or function, indicating
10. `void`: this type is commonly only used when defining the return type of a method or function, indicating
"nothing is returned", and thus the user should not rely on any returned value.

**Example 1:**
Expand Down Expand Up @@ -710,7 +712,7 @@ The following keywords are recognized by this PSR:
In this example, the function contains a return statement without a given value. Because there is no actual value
specified, this also qualifies as type `void`.

10. `null`: the element to which this type applies is a `NULL` value or, in technical terms, does not exist.
11. `null`: the element to which this type applies is a `NULL` value or, in technical terms, does not exist.

A big difference compared to `void` is that this type is used in any situation where the described element may at
any given time contain an explicit `NULL` value.
Expand Down Expand Up @@ -746,13 +748,13 @@ The following keywords are recognized by this PSR:
}
```

11. `callable`: the element to which this type applies is a pointer to a function call. This may be any type of callable
12. `callable`: the element to which this type applies is a pointer to a function call. This may be any type of callable
as defined in the PHP manual about [pseudo-types][PHP_PSEUDO] or the section on [callable][PHP_CALLABLE].

12. `false` or `true`: the element to which this type applies will have the value `TRUE` or `FALSE`. No other value will
13. `false` or `true`: the element to which this type applies will have the value `TRUE` or `FALSE`. No other value will
be returned from this element.

13. `self`: the element to which this type applies is of the same class in which the documented element is originally
14. `self`: the element to which this type applies is of the same class in which the documented element is originally
contained.

**Example:**
Expand All @@ -777,13 +779,13 @@ The following keywords are recognized by this PSR:
> of child classes with each representation of the class. This would make it obvious for the user which classes are
> acceptable as type.

14. `static`: the element to which this type applies is of the same class in which the documented element is contained,
15. `static`: the element to which this type applies is of the same class in which the documented element is contained,
or, when encountered in a subclass, is of type of that subclass instead of the original class.

This keyword behaves the same way as the [keyword for late static binding][PHP_OOP5LSB] (not the static method,
property, nor variable modifier) as defined by PHP.

15. `$this`: the element to which this type applies is the same exact instance as the current class in the given
16. `$this`: the element to which this type applies is the same exact instance as the current class in the given
context. As such, this type is a stricter version of `static`, because the returned instance must not only be
of the same class but also the same instance.

Expand All @@ -792,6 +794,7 @@ The following keywords are recognized by this PSR:
[RFC2119]: https://tools.ietf.org/html/rfc2119
[RFC5234]: https://tools.ietf.org/html/rfc5234
[PHP_RESOURCE]: https://php.net/manual/language.types.resource.php
[PHP_ITERABLE]: https://php.net/manual/language.types.iterable.php
[PHP_PSEUDO]: https://php.net/manual/language.pseudo-types.php
[PHP_CALLABLE]: https://php.net/manual/language.types.callable.php
[PHP_OOP5LSB]: https://php.net/manual/language.oop5.late-static-bindings.php
Expand Down

0 comments on commit 1b01816

Please sign in to comment.