I do try to get static variable of php class in different php files.
but when set variable in testpy.php then variable in taski.php is null.
This is testpy.php:
<?php
/**
* Created by PhpStorm.
* User: PC1
* Date: 9/16/2018
* Time: 3:00 PM
*/
include 'cacheData.php';
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_ERROR);
//echo $_POST["firstname"];
cacheData::$cacheArrayFirst = json_decode($_POST["firstname"]);
cacheData::converting(cacheData::$cacheArrayFirst);
echo json_encode(cacheData::$cacheArrayFinal);
this is taski.php:
<?php
/**
* Created by PhpStorm.
* User: hamed
* Date: 17/09/2018
* Time: 12:37
*/
include 'cacheData.php';
sleep(5);
echo json_encode(cacheData::returnValue());
this is cacheData.php:
<?php
/**
* Created by PhpStorm.
* User: PC1
* Date: 9/16/2018
* Time: 4:35 PM
*/
class cacheData
{
public static $cacheArrayFirst;
public static $cacheArrayFinal;
public static function converting($cacheArrayOne){
if (empty(cacheData::$cacheArrayFinal)){
cacheData::$cacheArrayFinal=$cacheArrayOne;
}
}
public static function returnValue(){
return self::$cacheArrayFinal;
}
}