rfc:class_properties_initialization
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:class_properties_initialization [2010/07/30 10:10] – first draft version k.antczak | rfc:class_properties_initialization [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
* Status: In Draft | * Status: In Draft | ||
* First Published at: http:// | * First Published at: http:// | ||
+ | * Related RFC: [[rfc: | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 12: | Line 13: | ||
==== Why do we need it? ==== | ==== Why do we need it? ==== | ||
- | * **annotations** | + | * **code readability** |
===== Proposal ===== | ===== Proposal ===== | ||
- | It's possible that this feature would be one of the best use with proposals: [[rfc:annotations]], | + | **Main idea** |
+ | |||
+ | <code php> | ||
+ | class Foo | ||
+ | { | ||
+ | private $var1 = function () { /* some callback ? */ } | ||
+ | |||
+ | private $var2 = array ( 'foo' => function () { /* some callback ? */ } ); | ||
+ | |||
+ | private httpRequest $var3 = NULL; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | instead | ||
+ | |||
+ | <code php> | ||
+ | class Foo | ||
+ | { | ||
+ | private $var1; | ||
+ | |||
+ | private $var2; | ||
+ | |||
+ | private $var3 = NULL; | ||
+ | |||
+ | public function __construct () | ||
+ | { | ||
+ | $this -> var1 = function () { /* some callback ? */ } | ||
+ | |||
+ | $this -> var2 = array ( ' | ||
+ | |||
+ | if ( ( $request = SomeCore | ||
+ | { | ||
+ | $this -> var3 = $request; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **Other / Related** | ||
+ | |||
+ | * objects structures - structured objects initialization - like IoC/DI containers, where structure is not a result of code execution, but it's a result of strictly controlled design. | ||
<code php> | <code php> | ||
Line 23: | Line 64: | ||
private $var1 = new Bar(); | private $var1 = new Bar(); | ||
- | private $var2 = function | + | private $var2 = Bar :: getInstance |
+ | } | ||
+ | </code> | ||
- | private $var3 = array ( ' | + | * initialization with functions |
- | | + | <code php> |
+ | class Foo | ||
+ | { | ||
+ | private $var1 = time (); | ||
+ | |||
+ | | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ===== Rejected initialization types ===== | ||
+ | |||
+ | <code php> | ||
+ | private $foo = $this -> someStuff(); | ||
</ | </ | ||
rfc/class_properties_initialization.1280484602.txt.gz · Last modified: 2017/09/22 13:28 (external edit)