Answer the question
In order to leave comments, you need to log in
Why is the object created twice?
Help to find the reason for the double object creation...
index.php
define( 'ACCESS', TRUE);
include_once("core/config.class.php");//подключаем класс настроек
include_once("core/core.class.php");//подключаем класс ядра(основных функций)
$core = new core();
if($_SERVER['REQUEST_URI'] != '/'){
$UrlParts = explode('/', trim($_SERVER['REQUEST_URI'], '/'));//чистим от "/"
$Module = array_shift($UrlParts);//отделяем имя модуля
if(count($UrlParts) % 2 == 0 && file_exists($core -> PATH_MODULE_FILE.$Module.'.php')){
for ($i=0; $i < count($UrlParts); $i++) {
$Options[$UrlParts[$i]] = $UrlParts[++$i];
}
}else{
$Module = 'c404';
$Options = FALSE;
}
}else{
header('Location: //'.$core -> SITE_URL.'/'.$core -> DEFAULT_MODULE);
}
require_once($core -> PATH_MODULE_FILE.$Module.'.php');
$controller = new $Module($Options);
echo $controller -> respaun.'</br>';
echo $Module.'</br>';
print_r($Options);
class core extends Settings{
protected $IndConnect = '';//идентификатор коннекта к базе данных
//подключение к БД
public function __construct(){
session_start();//включаем сессии
//подключаемся к БД
$dbconnect = @mysql_connect($this -> NAME_HOST, $this -> NAME_USER, $this -> PASS_USER);
if(!$dbconnect){
exit($this -> error('База не найдена: '.mysql_error()));
}
$this -> IndConnect = $dbconnect;
//выбираем БД
mysql_select_db($this -> NAME_DB, $dbconnect) or exit ($this -> error('Таблица не найдена: '.mysql_error()));
//ставим локаль
mysql_query("SET NAMES utf8");
}
//запись в лог ошибок
public function error($error){
$faleopen = fopen($this -> PATH_LOG_FILE, 'a');
$strip_text = '| '.date('H:m:s d.m.Y').' '.$error."\r\n";
fwrite($faleopen, $strip_text);
fclose($faleopen);
}
}
Answer the question
In order to leave comments, you need to log in
When you write code like this, I become a sad panda.
In fact, if, then the constructor should be called once, if this is really all the code that participates in all this bacchanalia. The easiest option would be to install xdebug, put a bug in the constructor and look at the call trace if it really is called twice. More sophisticated ways involve different combinations of var_dump and die in different parts of the code.
Yes, perhaps more than half is not written that way.
What prevents you from starting debugging through xdebug?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question