Abstracte classe word niet geinitieerd

Status
Niet open voor verdere reacties.

slabbetje

Gebruiker
Lid geworden
5 mei 2007
Berichten
290
Beste helpers
ik ben sinds kort bezig om aan te leren OOP te gaan programmeren nu wil ik een abstracte classe maken voor mijn View alleen hij geeft aan dat hij niet geiniteerd is.
Verder heb ik hier weinig kaas van gegeten omdat ik pas net begin met OOP dus zou iemand mij kunnen uitleggen wat ik fout doe?

Alvast bedankt,

Slabbetje

PHP:
Class Main
{
	public $Plugins = Array();	//Array for all the plugins
	public $Debug = true;		//Boolean if the debug mode is ON or OFF
	public $noOutput = false;	//Boolean if there comes a output ON or OFF
	
	//Constructor this will load all the plugins etc.
	public function __construct()
	{		
		$this -> Plugins = Array();
		$this -> loadClass( "errorHandler" , "./Engine/" , "Plugin");
		$this -> loadClass( "requestHandler" , "./Engine/" , "Plugin" );
		$this -> loadClass( "databaseHandler" , "./Engine/" , "Plugin" );
		
		try
		{
			require("Pages/View.php");
			$request_object = new View();
			$request_object = requestHandler::request();
			$view_className       =  $request_object;
			$viewReflector  =  new ReflectionClass($view_className);
			$scherm                 =  $viewReflector->newInstanceArgs(array(
				  $this
				, requestHandler::Request()
			));
		} catch (LogicException $error) {
		
		}
	}
	
	//This is the function for loading the plugins
	public function loadClass( $className, $classDir = "Pages", $classType = "Plugin")
	{
		if ( isset($this -> errorHandler) )
		{
			if ( file_exists( $classDir . $className . ".php" ) )
			{
				require( $classDir . $className . ".php" );
				$this -> $className = new $className( $this );
				$this -> errorHandler -> Error("[" . $classType . "] ". $className . " is succesfully loaded");
			} else {
				$this -> errorHandler -> Error("[" . $classType . "] Error loading " .$className. " Class");
			}
		} else {
			require( $classDir . $className . ".php" );
			$this -> $className = new $className( $this );
			$this -> errorHandler -> Error("[" . $classType . "] ". $className . " is succesfully loaded");
		}
	}
	
	public function __destruct()
	{
		$this-> errorHandler -> Error("[Global] Engine is succesfully loaded");
	}
	
}

PHP:
Abstract Class requestHandler
{
	public $PluginName = "requestHandler";
	public $Engine;
	private static $Request;
	private static $Action;
	
	
	public static function config()
	{
		//Spul returnen
		static $run;
		if (TRUE === $run)
		{
			return;
		}
		$run = TRUE;
		
		$request_string = str_replace(URL_BASE, "", $_SERVER['REQUEST_URI']);
		$request_array = explode("/", $request_string);
		$request = array_filter($request_array);
		
		if ( is_array($request) && 0 < count($request) && $request[0] != "index.php" )
		{
			self::$Request = array_shift($request);
		} else {
			self::$Request = 'Index';
		}
		
		self::$Action = $request;		
	}
	
	public static function request()
	{
		self::config();
		return self::$Request;
	}
	
	public static function get($i)
	{
		self::config();
		return self::$Action[$i];
	}
	
	public static function getAll()
	{
		self::config();
		return self::$Action;
	}
}
 
$this-variabelen horen met het pijltje er aan vast

Dus dit is fout:
PHP:
$this -> Plugins = Array();
$this -> loadClass( "errorHandler" , "./Engine/" , "Plugin");
$this -> loadClass( "requestHandler" , "./Engine/" , "Plugin" );
$this -> loadClass( "databaseHandler" , "./Engine/" , "Plugin" );

Dit hoort wel te werken
PHP:
$this->Plugins = Array();
$this->loadClass( "errorHandler" , "./Engine/" , "Plugin");
$this->loadClass( "requestHandler" , "./Engine/" , "Plugin" );
$this->loadClass( "databaseHandler" , "./Engine/" , "Plugin" );
 
Note: je kunt een Abstract Class niet instantieren. Je moet een gewone class hebben die hem extend en alle methodes implementeert.
 
Ah dat was het dus, ik had al zo'n vermoeden.

Even een naslagwerkje er bij gepakt maar daar diezelfde note niet gelezen:rolleyes:

Voorbeeld abstractie:
PHP:
abstract class Shape {
  function setCenter($x, $y) {
    $this->x = $x;
    $this->y = $y;
  }

  abstract function draw();

  protected $x, $y;
}

class Square extends Shape {
  function draw() {
    // Here goes the code which draws the Square
  }
}

class Circle extends Shape {
  function draw() {
    // Here goes the code which draws the Circle
  }
}
 
Oké het is nu idd gelukt stom van mij blijft leuk als je net met OOP begint
Verder maken spaties tussen functies "$this -> blablba" niet uit in PHP 4 > of dit ook in PHP 6 het geval is geen idee maar die is ook nog niet uit,
Net als dat je in php ook niet variable een type moet geven of het bijv. een number of string is
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan