How does an operation method under the same controller in TP call a variable in another operation method?

what if b wants to use the $time variable in a?

   public function a(){
      $time="1520452015";
      return $this->fetch();
   }
   public function b(){
     
   }
Mar.22,2021

  1. return $time as a return parameter
  2. set $time to the class variable $this- > time

Encapsulation learn about

public $time = '1520452015';
public function a()
{
  $time = $this->time;
  return $this->fetch();
}
public function b()
{
    var_dump($this->time);
}

you can put time in the properties of this class. A modifies the


private $time = 'xxxxx';
public function a()
{
  $time = $this->time;
  return $this->fetch();
}
public function b()
{
    dump($this->time);
}


private static $time = 'xxxxx';
public function a()
{
  $time = self::$time;
  return $this->fetch();
}
public function b()
{
    dump(self::$time);
}
that can also be read by b.
Menu