rfc:nested_classes

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:nested_classes [2013/10/02 08:20] – [Proposal] krakjoerfc:nested_classes [2013/10/13 18:59] – [PHP RFC: Nested Classes] krakjoe
Line 4: Line 4:
   * Date: 2013-09-29   * Date: 2013-09-29
   * Author: Joe Watkins, krakjoe@php.net   * Author: Joe Watkins, krakjoe@php.net
-  * Status: Under Discussion+  * Status: Withdrawn
   * First Published at: http://wiki.php.net/rfc/nested_classes   * First Published at: http://wiki.php.net/rfc/nested_classes
  
Line 214: Line 214:
 </code> </code>
  
-The protected class ''\foo\bar\baz'' can now be used in ''\foo''.+The protected class ''\foo\bar\baz'' can now be used in ''\foo'', for example: 
 + 
 +<code php> 
 +<?php 
 +/* 
 +* foo 
 +* @package foo 
 +*/ 
 +class foo 
 +
 +    /* 
 +    * foo\bar supporting class for foo 
 +    * @subpackage foo\bar 
 +    * @private 
 +    */ 
 +    private class bar 
 +    { 
 +  
 +        /* 
 +        * \foo\bar\baz supporting class for foo\bar 
 +        * @subpackage foo\bar\baz 
 +        * @protected 
 +        */ 
 +        protected class baz 
 +        { 
 +  
 +            public function __construct() { 
 +  
 +            } 
 +        } 
 +  
 +        public function __construct() { 
 +            $this->baz = new foo\bar\baz(); 
 +        } 
 +    } 
 +     
 +    /* 
 +    * \foo\qux supporting class for foo 
 +    */ 
 +    private class qux extends foo\bar\baz 
 +    { 
 +        public function __construct() { 
 +             
 +        } 
 +    } 
 +  
 +    /* PUBLIC API METHODS HERE */ 
 +  
 +    public function __construct() 
 +    { 
 +        $this->bar = new \foo\bar(); 
 +        $this->baz = new \foo\bar\baz(); 
 +        $this->qux = new \foo\qux(); 
 +    } 
 +
 +  
 +var_dump(new \foo()); 
 +</code> 
 + 
 +Output: 
 + 
 +<code> 
 +object(foo)#1 (3) { 
 +  ["bar"]=> 
 +  object(foo\bar)#2 (1) { 
 +    ["baz"]=> 
 +    object(foo\bar\baz)#3 (0) { 
 +    } 
 +  } 
 +  ["baz"]=> 
 +  object(foo\bar\baz)#4 (0) { 
 +  } 
 +  ["qux"]=> 
 +  object(foo\qux)#5 (0) { 
 +  } 
 +
 +</code>
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
rfc/nested_classes.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1