But anyways, I'm reading about interfaces and I'm just wondering, what's the point? All I know about them is that omit an error when it contains a function that isn't in the class it's implemented in.
So why would someone use an interface? What are the benefits?
Also what are the point of namespaces? Should I be using them?
Also here's my current setup/framework for programming. It's probably not exactly the best way of doing things but it's worked so far. I want to know if I'm doing something horribly wrong or not.
File structure:
c/
index.php
inc/
autoload.php
startup.php
framework.class.php
m/
v/
css/
(css files)
js/
(javascript files)
index.php
index.php
/index.php contains:
<?php
require_once("c/index.php");
new page();
?>
c/index.php contains:
<?php
class page {
public function __construct(){
try {
require_once('inc/startup.php');
$framework = new framework();
$content = ''; // Predefined to prevent Undefined Variable notices
if(isset($_GET['pageofprogram__'])){
$page = preg_replace("[^A-Za-z0-9]", "", $_GET['pageofprogram__']);
} else {
$page = "default";
}
if(file_exists('m/' . $page . '.php')){
include('m/' . $page . '.php');
} else {
include('m/404.php');
}
include('v/index.php');
} catch (Exception $e){
echo "There was a problem with the program.<br>Check the exceptions log for more info.";
file_put_contents("data/errors/exceptions.log", date("Y-m-d H:i:s e") . "\r\n" . print_r($e, true) . "\r\n\r\n", FILE_APPEND);
}
}
}
?>
inc/startup.php contains:
<?php
if(!isset($_SESSION)){
session_start();
}
require_once("autoload.php"); // Autoload so $framework functions work
?>
inc/autoload.php contains:
<?php
function __autoload($class){
if(file_exists('inc/' . $class . '.class.php')){
if(!(include('inc/' . $class . '.class.php')) == 'OK'){
throw new Exception("Could not load class " + $class);
}
} else {
throw new Exception("Could not find class " + $class);
}
}
?>
inc/framework.class.php contains:
<?php
/*
* framework.class.php
* Not exactly a framework, per se, but used to access other classes in a dynamic fashion.
*/
class framework {
public function get($class){
if(!isset($this->$class)){
try {
$this->$class = new $class();
} catch(Exception $e){
/* TODO: ERROR HANDLING */
die("Fatal error: " + $e->getMessage());
}
}
return $this->$class;
}
}
?>
As you can see this uses the MVC framework style. Using $framework, I can call any class that is in inc/ using $framework->get('theclass'), and it'll return theclass. This way I don't have to manually include/create them.
This post has been edited by creativecoding: 19 September 2012 - 06:30 PM

New Topic/Question
Reply





MultiQuote









|