Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    144
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Why is my class throwing warnings?

    Why is this code throwing the following errors? Thanks.

    Code:
    <?
    class DirTree {
    
        /**
         * Get a tree of folders and files from a spec dir
         * @returns An ArrayCollection of Tree
         */
    	function DirTree($dir_tree) {
    		$_tree = $this->parse_dir($dir_tree);
    		return $_tree;
    	}
    
        /**
         * Get a tree of folders and files from a spec dir
         * @returns An Array of Tree
         */
    	function parse_dir($folder) {
    
    		$dir                = @opendir($folder);
    		$filecount          = 0;
    		$foldercount		= 0;
    		$tree				= array();
    		$limb				= array();
    		$cnt				= 0;
    
    		while(false != ($item = @readdir($dir))) {
    
    			if($item == "." || $item == "..") continue;
    
    			if(is_dir("$folder/$item")){
    
    				$tmpTree = new DirTree();
    
    				$limb['sub_folder'][]['folder_name'] = $item;
    				$limb['sub_folder'][] = $tmpTree->parse_dir("$folder/$item");
    
    				$foldercount++;
    				$limb['folders'][] = $foldercount;
    
    				$filecount++;
    				$limb['files'][] = $filecount;
    				//continue;
    
    			}else{
    
    				$limb['file_name'][] = $item;
    
    			}
    		}
    
    		$tree[] = $limb;
    		$cnt++;
    		return $tree;
    
    	}
    }
    
    $class = new DirTree();
    
    /* view array  */
    echo "<pre>";
    print_r($class->DirTree("../../core/amf/app"));
    echo "</pre>*****************************************************************";
    ?>
    Warning: Missing argument 1 for DirTree::DirTree() in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 8

    Notice: Undefined variable: dir_tree in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 9

    Warning: Missing argument 1 for DirTree::DirTree() in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 8

    Notice: Undefined variable: dir_tree in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 9

    Warning: Missing argument 1 for DirTree::DirTree() in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 8

    Notice: Undefined variable: dir_tree in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 9

    Warning: Missing argument 1 for DirTree::DirTree() in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 8

    Notice: Undefined variable: dir_tree in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 9

    Warning: Missing argument 1 for DirTree::DirTree() in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 8

    Notice: Undefined variable: dir_tree in C:\apache2triad\htdocs\flashservices_v1.9\services\folder_tree\dir_tree2.php on line 9

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    DirTree is a constructor, and there is no default constructor supplied. Calls to object instantiation require the parameter $dir_tree to be added.
    Both your $class and your $tmpTree require an argument to be valid. Otherwise, create a default constructor for the class.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •