rfc:property_accessors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:property_accessors [2021/05/04 13:35] – nikic | rfc:property_accessors [2022/04/28 09:30] (current) – Fix typos ilutov | ||
---|---|---|---|
Line 363: | Line 363: | ||
</ | </ | ||
- | Specifying the same accessor multiple | + | Specifying the same accessor multiple |
=== By-reference getter === | === By-reference getter === | ||
Line 387: | Line 387: | ||
</ | </ | ||
- | These indirect | + | These indirect |
However, indirect array modification, | However, indirect array modification, | ||
Line 565: | Line 565: | ||
public int|string $covariant { get; } | public int|string $covariant { get; } | ||
// This property is useless, but will serve for the sake of illustration. | // This property is useless, but will serve for the sake of illustration. | ||
- | public int|string $contravariant { set {} } | + | public int|string $contravariant { set { /* ... */ } } |
} | } | ||
Line 920: | Line 920: | ||
class Test { | class Test { | ||
// Illegal: Implicit get, explicit set. | // Illegal: Implicit get, explicit set. | ||
- | public string $prop { get; set {} } | + | public string $prop { |
+ | | ||
+ | | ||
+ | | ||
// Illegal: Implicit set, explicit get. | // Illegal: Implicit set, explicit get. | ||
- | public string $prop { get {} set; } | + | public string $prop { |
+ | | ||
+ | | ||
+ | | ||
} | } | ||
</ | </ | ||
Line 945: | Line 951: | ||
// Illegal: Default value on property with explicit accessors. | // Illegal: Default value on property with explicit accessors. | ||
public $prop = "" | public $prop = "" | ||
- | get {} | + | get { /* ... */ } |
} | } | ||
} | } | ||
Line 978: | Line 984: | ||
This limitation exists to prevent embedding of very large property declarations in the constructor signature. | This limitation exists to prevent embedding of very large property declarations in the constructor signature. | ||
- | === var_dump, get_object_vars() etc === | + | === var_dump(), array cast, foreach |
- | '' | + | '' |
<PHP> | <PHP> | ||
Line 994: | Line 1000: | ||
// | // | ||
// } | // } | ||
+ | |||
+ | var_dump((array) $test); | ||
+ | // array(1) { | ||
+ | // | ||
+ | // | ||
+ | // } | ||
+ | |||
+ | foreach ($test as $name => $value) { | ||
+ | echo " | ||
+ | } | ||
+ | // prop1: 42 | ||
</ | </ | ||
rfc/property_accessors.1620135342.txt.gz · Last modified: 2021/05/04 13:35 by nikic