umaxim
asked on
Redeclare Problem
Hi i have this kind of script for CI
SO it load class and then run it. The problem when i run script once it fine. But when i run script second time with the same class name it give me error Fatal error: Cannot redeclare class Banners in /httpdocs/application/widg ets/banner s.php on line 20
So question is it any way to make class end and then run again.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Widget
{
public $module_path;
function run($file) {
$args = func_get_args();
$module = '';
/* is module in filename? */
if (($pos = strrpos($file, '/')) !== FALSE) {
$module = substr($file, 0, $pos);
$file = substr($file, $pos + 1);
}
include './application/widgets/'.$file.".php";
$file = ucfirst($file);
$widget = new $file();
global $widget;
$widget->module_path = $path;
return call_user_func_array(array($widget, 'run'), array_slice($args, 1));
}
function render($view, $data = array()) {
extract($data);
include './application/widgets/views/'.$view.EXT;
}
function load($object) {
$this->$object = load_class(ucfirst($object));
}
function __get($var) {
global $CI;
return $CI->$var;
}
}
SO it load class and then run it. The problem when i run script once it fine. But when i run script second time with the same class name it give me error Fatal error: Cannot redeclare class Banners in /httpdocs/application/widg
So question is it any way to make class end and then run again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think erdincgc is on the right path. Another possibility is to consider using include_once() when you only want one copy of a file included, such as when the file contains a function or class definition.