Php7: PHP7: Anonymous class: like anonymous functions, the anonymous class creates a one-time simple object. echo
Like anonymous functions, an anonymous class creates a one-time simple object.
'; Echo ''; classcommon {public $ default = 10; function _ construct ($ key) {$ this-> getVal ($ key);} publicfunctiongetVal (int $ I): int {$ this-> default + = $ I; return $ this-> default + 0.1;} echo 'famous function'; echo'
'; $ Com = new common (1); echo $ com-> getVal (2.2 ). '--'; echo $ com-> getVal (2.2 ). '--'; echo (new common (1)-> getVal (8.9); echo ''; echo 'anonymous class '; // to define an anonymous class, echo (newclass (1) extendscommon {})-> getVal (90); echo 'must be inherited'
'; Echo (newclass (2) extendscommon {})-> getVal (90 );
After an anonymous Class is nested in a common class, you cannot access
Private, protected (protected) methods or attributes. To access the external class (Outer class) protected
An anonymous class can be extend (extended. To use the private
Attribute, which must be passed in through the constructor:
prop) extendsOuter {private $prop3; public function __construct($prop) { $this->prop3 = $prop; } public function func3() { return $this->prop2 + $this->prop3 + $this->func1(); } }; }}echo (new Outer)->func2()->func3();//6
An anonymous function can implement closures, so the corresponding anonymous class can also implement closures.
'; } publicfunctiongetVal($index){$this->index = $index; echo$this->index; } publicfunctiongetIndex(){echo$this->index; } };}$arr[2]->getVal(2);echo'
';var_dump($arr[1]);$arr[1]->getIndex();
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the anonymous PHP 7 class, including the PHP7 content, hope to be helpful to friends who are interested in PHP tutorials.