V
V
Vladislav2014-08-23 12:59:32
Android
Vladislav, 2014-08-23 12:59:32

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);

core.class.php
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);
  }
}

the error is written to a file...and so, for some reason, the core object is created twice...i.e. all actions in __construct are performed twice...
What did I write wrong?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
H
HamSter, 2016-07-07
@HamSter007

animation width\height

A
Artem Gapchenko, 2016-07-07
@artemgapchenko

Dig towards Activity Transitions with shared elements.

S
Sergey, 2014-08-23
@DubecZ

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.

A
Alexander Kubintsev, 2014-08-23
@akubintsev

Yes, perhaps more than half is not written that way.
What prevents you from starting debugging through xdebug?

M
Melkij, 2014-08-23
@melkij

And banal: check the access log that the script itself is called the same number of times as you want.
PS: stop raping for a decade as a rotten mysql_*. Use modern PDO or mysqli.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question