53rd Day Rest object, directory read, recursive

Source: Internet
Author: User

Encapsulation: Self-made private object and function control

classjundui{Private $JM; Private $rs; Private $wq; Private $NL; Private $GX; function__set ($i,$j)    {        if($i= = "JM")            $this->jm=$j; Else if($i= = "Wq")            $this->wq=$j; Else if($i= = "RS")        {            if(Is_int($j))                $this->rs=$j; Else                $this->rs=false; }        Else if($i= = "NL")        {            if(Is_int($j) &&$j>18&&$j<55)                $this->nl=$j; Else                $this->nl=false; }        Else if($i= = "GX")        {            if($j= = "Enemy" | |$j= = "Friends")                 $this->gx=$j; Else                 $this->gx=false; }    }}$a=NewJundui;$a->jm= "Chinese Red Army";$a->rs=1000000;$a->wq= "machine guns, tanks, airplanes, missiles, atomic bombs";$a->nl=132;$a->gx= "Friends";Var_dump($a);

Simple recursive functions and calls (recursive functions have in-and-out, repeated execution)

Calling yourself in a function is called recursive function test ($i) {    echo $i. ' <br> ';    if ($i >0)        Test ($i-1);    else        echo "__________<br>";    echo $i. ' <br> ';} Test (ten);     

Recursive traversal of directory functions and Invocation methods

functionFordir ($name)//define function Names{    $i=Opendir($name);//Open Directory    Readdir($i);//gets the first table of contents.    Readdir($i);//gets the second directory :     while($j=Readdir($i))//start the loop from the third file, and return to Flase when the directory is fully retrieved, followed by a vulgar    {        $j=$name." /".$j;//get the directory under directory        if(Is_dir($j))//determine if a file is a directory file{
EchoDirectory$j}<br> ";//Output File name
Fordir ($J); The repeated call function has reached the subdirectory of all subdirectories under all subdirectories under the Read directory ...
}Else EchoFile$j}<br> ";//Output File name } Closedir($i);}$name= "./mulu";//Gets the directory path, in quotation marks before the name of the directory to be added "/."Fordir ($name)//calling Functions

Functions that call other text (Include,require)

include "function. File name";  // file name is the file path where the function is located, can be other formats, generally used to invoke according to the condition and little impact on the program, a warning when the code is wrong
include_once "function. File name";  //When called multiple times, the default is called only once
require"function, file name";  //used to have a significant impact on the program, when the calling failed program cannot execute, a fatal error occurs when the calling code is wrong
require_once"function. File name";   //When called multiple times, the default is called only once

anonymous function ($name an object belonging to the built-in class closure)

$name=function($i,$j) {    echo "This is an anonymous function";     return $i*$j;};                           // function to add a semicolon  Echo $name (2,3);                       //This call is the same as the effect below
Echo $name (2,function () {return 3;}) the//anonymous function can be used as a function parameter

Find the first occurrence of global variable $ A value

Global $a

Closure function (unstable)

functionFather ()//declaring a parent function{    $a=1; $b=2; $son=function($i) Use(&$a,&$b)       //declare an anonymous function as a child function, the child function must not have a return value//the child function calls the parent function of the variable, the addition of the address character in order to let the variable in the parent function global change, not add only the assignment, do not change the function of the parent function global variables    {        Echo $i.‘ <br> '; $a++; $b++; Echo $a*$b.‘ <br> ';     }; return $son;//use a child function as the return value}$father=father ();//when called, the function internal variable is not freed$father("Call the first time"); //Because the variable is not released, every call, the parent function variable $ A, $b has been changing $father("Call the second time");$father("Call the third time");

53rd Day Rest object, directory read, recursive

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.