Post by chameleon121 » Sat Nov 28, 2015 3:07 am

I am trying to add a function to the class and I keep getting a parse error on the last line (unexpected T_VARIABLE, expecting T_FUNCTION), If i use this outside the class, works fine. I guess I don't understand classes properly.

Code: Select all

<?php
class ModelCheckoutOrder extends Model {
    public function directoryToArray($directory, $recursive = false, $listDirs = true, $listFiles = true, $exclude = '') {
        $arrayItems = array();
        $skipByExclude = false;
        $handle = opendir($directory);
        if ($handle) {
            while (false !== ($file = readdir($handle))) {
            preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip);
            if($exclude){
                preg_match($exclude, $file, $skipByExclude);
            }
            if (!$skip && !$skipByExclude) {
                if (is_dir($directory . $file)) {
                    if($recursive) {
                        $arrayItems = array_merge($arrayItems, directoryToArray($directory. $file, $recursive, $listDirs, $listFiles, $exclude));
                    }
                    if($listDirs){
                        $file = $directory . $file;
                        $arrayItems[] = $file;
                    }
                } else {
                    if($listFiles){
                        $file = $directory . $file;
                        $arrayItems[] = $file;
                    }
                }
            }
        }
        closedir($handle);
        }
        return $arrayItems;
    }
	$files_array = $this->directoryToArray(DIR_FILES);

Newbie

Posts

Joined
Mon Jan 19, 2015 4:04 am
Who is online

Users browsing this forum: No registered users and 6 guests