rfc:class_properties_initialization

This is an old revision of the document!


Request for Comments: Class properties initialization

Introduction

The purpose of this feature is to provide more advanced way to initialize class properties using closures, objects, type hinting.

Why do we need it?

  • objects structures - structured objects initialization

Proposal

class Foo
{
    private $var1 = new Bar();
    private $var2 = Bar :: getInstance ();
 
    private $var3 = time ();
 
    private $var4 = function () { /* some callback ? */ }
 
    private $var5 = array ( 'foo' => function () { /* some callback ? */ } );
 
    private httpRequest $var6 = NULL;
    private httpRequest $var7 = getRequest ();
}

Rejected initialization types

private $foo = $this -> someStuff(); // impossible/to weird (?)

Changelog

2010-07-30 k.antczak Initial RFC creation.

rfc/class_properties_initialization.1280485374.txt.gz · Last modified: 2017/09/22 13:28 (external edit)