rfc:structured_object_notation

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:structured_object_notation [2016/07/31 08:36] – created midorikocakrfc:structured_object_notation [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 86: Line 86:
 Let's have one class called B, similar to above example. Let's have one class called B, similar to above example.
  
 +<code php>
 +class B{
  
-Instead of instantiating objects on the fly, here I propose a structured definition of an object using this syntax:+    // No way to define order of methods 
 +    public function __construct($world = "world"){ 
 +        echo "Hello ". $world."\n"; 
 +        echo "You can foo and you can bar\n"; 
 +    }
  
 +    public function foo($x, $y){
 +        echo "\nYou did foo: x is ".$x." and y is ".$y."\n";
 +        echo "Now you can bar\n";
 +    }
  
 +    public function bar($z, $t){
 +        echo "\nYou did bar: z is ".$z." and t is ".$t."\n";
 +        echo "You can bar again or end the program\n";
 +    }
  
-===== Backward Incompatible Changes ===== +    public function __destruct(){ 
-What breaks, and what is the justification for it?+        echo "\nGood bye\n"; 
 +    } 
 +}
  
-===== Proposed PHP Version(s===== +// Here comes the spaghetti 
-List the proposed PHP versions that the feature will be included in.  Use relative versions such as "next PHP 7.x" or "next PHP 7.x.y".+$app new B("midori"); 
 +$app->foo(1,2); 
 +$app->bar(3,4); 
 +</code>
  
-===== RFC Impact ===== 
-==== To SAPIs ==== 
-Describe the impact to CLI, Development web server, embedded PHP etc. 
  
-==== To Existing Extensions ==== +Instead of instantiating objects on the fly, here I propose a structured definition of an object using this syntax: 
-Will existing extensions be affected?+<code php> 
 +object $app instanceof B{ 
 +    $world "midori"; 
 +    // allowed methods comes after method definition 
 +    // in the beginning state allowed methods are foo and bar 
 +    public function __construct($world){ 
 +        // if method body is implemented, 
 +        // parent class method run automatically 
 +        // object method runs after. 
 +        // This block runs $app new B($world); 
 +        $this->foo(1,2); 
 +    }(foo, bar);
  
-==== To Opcache ==== +    // The only allowed method is bar in this state 
-It is necessary to develop RFC's with opcache in mindsince opcache is a core extension distributed with PHP.+    public function foo(1,2)(bar);
  
-Please explain how you have verified your RFC's compatibility with opcache.+    // if allowed methods are empty or not defined 
 +    // object is destructed 
 +    public function bar(3,4){ 
 +    }; 
 +
 +</code>
  
-==== New Constants ==== +An object can be instance of a class, if it's not defined, is instance of an anonymous class.
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation.+
  
-==== php.ini Defaults ==== +===== Backward Incompatible Changes ===== 
-If there are any php.ini settings then list: +Is a new featureMostly a syntactic sugar thanks to anonymous classesAll of the suggested syntax can be written using PHP 7.1
-  * hardcoded default values +
-  * php.ini-development values +
-  * php.ini-production values+
  
-===== Open Issues ===== +===== Proposed PHP Version(s) ===== 
-Make sure there are no open issues when the vote starts!+PHP 7.2
  
-===== Unaffected PHP Functionality ===== +===== RFC Impact ===== 
-List existing areas/features of PHP that will not be changed by the RFC. +==== To SAPIs ==== 
- +Better objects with states and defines allowed method order.
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.+
  
 ===== Future Scope ===== ===== Future Scope =====
-This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.+Allowed methods can have typed parameters. Ide's can use the object notation for autocompletion. Also an object can tell allowed methods using magic method like __help() when $app->help() is called.
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-Include these so readers know where you are heading and can discuss the proposed voting options. +As this is a language change, a 2/3 majority is requiredA straight Yes/No vote is being held.State
- +
-State whether this project requires a 2/3 or 50%+1 majority (see [[voting]]) +
- +
-===== Patches and Tests ===== +
-Links to any external patches and tests go here. +
- +
-If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed. +
- +
-Make it clear if the patch is intended to be the final patch, or is just a prototype.+
  
 ===== Implementation ===== ===== Implementation =====
-After the project is implemented, this section should contain  +No implementation still.
-  - the version(s) it was merged to +
-  - a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature+
  
 ===== References ===== ===== References =====
Line 153: Line 168:
  
 ===== Rejected Features ===== ===== Rejected Features =====
-Keep this updated with features that were discussed on the mail lists.+NA.
rfc/structured_object_notation.1469954161.txt.gz · Last modified: 2017/09/22 13:28 (external edit)