rfc:class_properties_initialization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:class_properties_initialization [2010/07/30 09:52] – created k.antczakrfc: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://wiki.php.net/rfc/class_properties_initialization   * First Published at: http://wiki.php.net/rfc/class_properties_initialization
 +  * Related RFC: [[rfc:annotations]], [[rfc:returntypehint]]
  
 ===== Introduction ===== ===== Introduction =====
  
-The purpose of RFCs are to work collaboratively towards a specification and finally an implementation of an idea.+The purpose of this feature is to provide more advanced way to initialize class properties using closures, objects, type hinting.
  
-==== Why do we need RFCs? ====+==== Why do we need it? ====
  
-They serve to keep a summary of on going discussions. This way people can keep an overview of the state of the discussion. Even if never put into place in the end, they also serve as a historical log of discussions that is much easier to read compared to mailinglist threads.+  * **code readability**
  
-===== Common Misconceptions =====+===== Proposal =====
  
-RFCs do not in any way replace discussions on the mailing list.+**Main idea**
  
-===== Proposal and Patch =====+<code php> 
 +class Foo 
 +
 +    private $var1 function () { /* some callback ? */ }
  
-Nothing needs to be patched here. Just use this template at your discretion.+    private $var2 = array ( 'foo' => function () { /* some callback ? */ } );
  
-==== Rejected Features ====+    private httpRequest $var3 NULL; 
 +
 +</code>
  
-Automated voting system.+instead of:
  
-==== More about RFCs ====+<code php> 
 +class Foo 
 +
 +    private $var1;
  
-http://en.wikipedia.org/wiki/Request_for_Comments+    private $var2;
  
-===== Changelog =====+    private $var3 NULL;
  
 +    public function __construct ()
 +    {
 +        $this -> var1 = function () { /* some callback ? */ }
 +        
 +        $this -> var2 = array ( 'foo' => function () { /* some callback ? */ } );
  
 +        if ( ( $request = SomeCore :: getRequest () ) instanceof httpRequest )
 +        {
 +            $this -> var3 = $request;
 +        }
 +    }
 +}
 +</code>
 +
 +**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>
 +class Foo
 +{
 +    private $var1 = new Bar();
 +
 +    private $var2 = Bar :: getInstance ();
 +}
 +</code>
 +
 +* initialization with functions
 +
 +<code php>
 +class Foo
 +{
 +    private $var1 = time ();
 +    
 +    private httpRequest $var2 = getRequest ();
 +}
 +</code>
 +
 +===== Rejected initialization types =====
 +
 +<code php>
 +private $foo = $this -> someStuff(); // impossible/nonsense (?)
 +</code>
 +
 +===== Changelog =====
  
 +2010-07-30 k.antczak Initial RFC creation.
rfc/class_properties_initialization.1280483572.txt.gz · Last modified: 2017/09/22 13:28 (external edit)