title: Php variable accessed from class in another file empty
body: <p>I am new to php and I am trying to program an app that uses php as backend. I don't really have an error in my code but I can't figure something out I have search but nothing has helped.there maybe be a solution but I can't find it.
  I have 3 php file</p>
  <p><code>Index.php</code></p>
  <pre><code>&lt;?php 
  include &quot;methods.php&quot;;
  $user=new user();
  if (isset($_GET[&quot;action&quot;])) {
    // code...
    switch ($_GET[&quot;action&quot;]) {
      case 'login':
        // code...
        $user-&gt;login();
        break;
      default:
        // code...
        echo(&quot;error 404&quot;);
        break;
    }
  
  } else {
    // code...
    echo(&quot;error 404&quot;);
  }
  
  ?&gt;
  </code></pre>
  <p><code>Methods.php</code></p>
  <pre><code>&lt;?php
  include &quot;extra.php&quot;;
  class user {
    public function login() {
      $input = new input();
      $error = &quot;fucked&quot;;
      $validationresult = json_decode($input-&gt;validateinput(), true);
      echo var_dump($validationresult);
      $validated = $validationresult[&quot;validated&quot;];
      if ($validated) {
        // code...
        echo (&quot;yes&quot;);
  
      } else {
        echo var_dump($validationresult);
      //  echo json_encode(($validationresult[&quot;error&quot;]));
      }
    }
  }
  ?&gt;
  </code></pre>
  <p><code>extra.php</code></p>
  <pre><code>&lt;?php
  class input {
    public $password;
    public $status;
    public $validated;
    public function __construct()
    {
      // code...
    }
    public function validateinput () {
      $password = $_GET[&quot;password&quot;];
     $this-&gt; $status = &quot;red&quot;;
      $this-&gt;$validated = false;
      echo($this-&gt; $status);
      return json_encode('{
      &quot;validated&quot;:'.$this-&gt;get_validate().',
      &quot;error&quot;:{
      &quot;status&quot;:&quot;'.$this-&gt;$status.'&quot;,
       &quot;username&quot;:&quot;ok&quot;,
       &quot;password&quot;:&quot;cannot be more than 5&quot;
      }
    }');
  
    }
  public function get_validate(){
  return $this-&gt;$validated;
  }
  }
  ?&gt;
  </code></pre>
  <p>As you can see in <code>index.php</code> I called <code>$user-&gt;login();</code>
  From <code>methods.php</code> which echos JSON <code>$input-&gt;validateinput()</code> from file <code>extra.php</code>.
  But</p>
  <pre><code>&quot;validated&quot;:'.$this-&gt;get_validate().'
  </code></pre>
  <p>And</p>
  <pre><code>&quot;status&quot;:&quot;'.$this-&gt;$status.'
  </code></pre>
  <p>From <code>extra.php</code>
  Is empty
  I don't why it is empty and the internet confuses me more.
  I am sorry for my grammatical mistakes as I am typing from a mobile phone and English isn't my first language.</p>