public static function readAll() { if (self::$categories !== false) { return self::$categories; } $fd = fopen(self::CategoryFileName, 'r'); if ($fd == null) { throw new Exception('File: ' . self::CategoryFileName . ' cannot be opened for reading.'); } self::$categories = array(); while (!feof($fd)) { $line = fgets($fd); if (strlen(trim($line)) == 0) { continue; } $parts = explode('=', $line); $idNameParts = explode(',', $parts[0]); $category = new Category($idNameParts[0], $idNameParts[1]); $parts = explode(';', trim($parts[1])); foreach ($parts as $part) { $category->addTransactionDescription(substr($part, 1, strlen($part) - 2)); } self::$categories[$category->id] = $category; } return self::$categories; }