dimanche 3 décembre 2017

Trying to return the recursive function. it does echo , just not return

i made a class to manage folder, a new folder is created every day if it is not already exist.

class manage_folder{

protected $root = "";
protected $path = "";

function __construct($root,$path){
    $this->root = $root;    #IGNORE ME! IAM NOT BEING USED!
    $this->path = $path;    #path to the media library outside the root folder 
}

function verify_pp(){  
        $path = $this->path;
        if (file_exists($new_path = $path."pp"."/".date("Y/m/d/"))){
            if (file_exists($new_path."4x4") && file_exists($new_path."12x12") && file_exists($new_path."original")){
                #I check if these folder exist just like him ^
                echo "i get printed even if function don't return";
                return "I don't want to get returned";  #I am the trouble maker

            }

            else{
                mkdir($new_path."4x4",0777,true);
                mkdir($new_path."12x12",0777,true);
                mkdir($new_path."original",0777,true);
                $this->verify_pp();
            }
        }

        else{
            if(mkdir($path."pp"."/".date("Y")."/".date("m")."/".date("d")."/",0777,true)){
                $this->verify_pp();
            }
        }
}

}

i want the function to return even after it goes through recursive. basically if there is no folders, create folder and return. if folders exist, just return. interestingly, the echo i put to test do get printed every time, but it wont return if folders are created and recur back to return. if the folder did exist already, it does get returned.

it needs to be returned no matter if it goes through recur and make folders or if folders exist already.

I apologize in advance if i posted something wrong or bad English. not my first language and I am not a professional programmer. just hobby.

Aucun commentaire:

Enregistrer un commentaire