Q:

set value for property in func1, get value of property in func2 PHP7

I am new to php7 and I am using MVC.
This is the story:
Server sends user a keyCode by Ajax (method A). Then user sends the keyCode by form to (method B). I have saved the keyCode to property named $beforCode in method A. Now I want to check the keyCode, which user sent me, in method B. BUT the problem is in method B I can't get the value of property keyCode which I have saved in method A. The property keyCode is empty.
here is my code:
class Payment extends Controller{

    public $keyCode = '';

    function setUserKeyCode(){ /// method A

        $code = $this->model->getKey();
        $this->keyCode = $code;

        /// echo $this->keyCode |  $this->keyCode equaled with $code
        echo $code; /// user get this by AJAX
    }

    function checkKeyCode(){ /// method B

         $userSentCode = $_POST['meKey']; /// user send this by Form
         $Key = $this->keyCode; /// echo $Key | $key = ''     <--- problem

         if ($clientCode == $key ) {
             echo 'user is valid';
         } 
         else {
             echo 'user is NON-valid';
         }
    }

}

*****If anybody has any other way to apply this job, please tell me.
thank you all

A:

It's because you ajax action and the user's post action are not in the same process, PHP use different processes for different requests. It's not the same Payment object so you can not get the key.
For your problem, I suggest saving the key value to the session.
session_start();
$_SESSION["code"]=$code;

And getting it :
session_start();
$code = $_SESSION["code"];

