i'm using MVC pattren and start the sessions in the construct of the Controller class . my class (expect core's one) are loaded by spl_autoload_register(). i create an AJAX class that's a subclass of the Controller in order to prevent user from executing multiple ajax request in a short interval of time i use the following code
class ajax extends Controller
{
public function __construct()
{
parent::__construct(false);
if ($this->checkAttempts())
exit();
}
public function checkAttempts()
{
$counter = 0;
$attempts = Session::get(AJAX);
$attempts = ($attempts === false) ? [] : $attempts;
if ($attempts === false)
Session::set(AJAX, []);
else
$this->setAttempt();
foreach ($attempts as $key => $attempt)
{
if (time() - intval($attempt) <= 10)
$counter++;
else
Session::destroyArray(AJAX, $key);
}
return $counter >= 5;
}
public function setAttempt()
{
return Session::setArray(AJAX, time());
}
//ajax methods ...
}
the problem is when i open another Controller such as home (haven't a construct)
class home extends Controller {
public function index(){...}
}
the script initialize the sessions in the checkAttepmt method of the ajax class it mean the method checkAttepmt it called and only the session are set for eg when i echo something nothing appear !
when i print the session variable in Home controller i found the session set in the ajax controller exists ( i clear them in each test ) .
i used debug_backtrace() like this to figure out the problem
class ajax extends Controller
{
public function __construct()
{
parent::__construct(false);
$_SESSION['trace'] = debug_backtrace();
}
}
the result is
[trace] => Array
(
[0] => Array
(
[file] => D:\__path__\application\core\application.php
[line] => 24
[function] => __construct
[class] => ajax
[object] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => ajax
)
[type] => ->
[args] => Array
(
)
)
[1] => Array
(
[file] => D:\__path__\public\index.php
[line] => 15
[function] => __construct
[class] => Application
[object] => Application Object
(
[controller:protected] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => ajax
)
[method:protected] => getConfirmMsg
[params:protected] => Array
(
)
)
[type] => ->
[args] => Array
(
)
)
what's the relation between the __PHP_Incomplete_Class and this problem and how to slove it ?