PHP7 anonymous php7.0php7 compiling and installation apachephp7.0 configuration

Source: Internet
Author: User
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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.