how to get variable between function of class?

Discussion in 'PHP' started by frozenade, Dec 2, 2007.

  1. #1
    dear all,

    i wrote this script, but there's an error with my script.

    class firstclass { 
    
       var $tmpdir; 
    
       function definetemp() { 
         $this->tmpdir = "tmp"; 
       } 
    
       function deltree($path) { 
         if (is_dir($path)) { 
            $entries = scandir($path); 
            foreach ($entries as $entry) { 
               if ($entry != '.' && $entry != '..') { 
                  deltree($path.DIRECTORY_SEPARATOR.$entry); 
               } 
            } 
         rmdir($path); 
         } 
         else { 
            unlink($path); 
         } 
       } 
    
    } 
    
    $classone = new firstclass(); 
    
    class secondclass { 
    
       function action(){ 
         global $classone; 
         // ? -> this should do action of deltree function <- ? 
         $classone->deltree($classone->tmpdir);
       } 
    
       function whatever(){ 
         // ... 
       } 
    
    } 
    
    $classtwo = new secondclass(); 
    
    
    // call action function 
    $classtwo->action(); 
    PHP:
    thank you very much for any kind of help.

    best regards
     
    frozenade, Dec 2, 2007 IP
  2. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    But what does the error return? Or what are you seeing?
     
    darkmessiah, Dec 2, 2007 IP
  3. krampus

    krampus Active Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #3
    it gives this error
    "Warning: unlink() [function.unlink]: No such file or directory in ..... on line 30"

    probably because you defined the path as TMP.. and that is not a folder... because there is "is_dir" function on function deltree... I think it is the problem :)
     
    krampus, Dec 2, 2007 IP