user3319781
user3319781

Reputation: 37

public static function php pass variable

I need to pass a variable from a static function to another within the same class. I do not write the full code, I need the theoretical procedure

enter code here

class One
{

public static function One()
{
/**
*  some code extract from DB $one
*/
}

public static function two()
{
/**
*  I need to retrieve the variable $one to use it in another query DB
*/
}

}

Note:

you can't use $this in a static function

Upvotes: 1

Views: 2128

Answers (2)

Adam W
Adam W

Reputation: 126

You need to declare your variable within your One class, then you can retrieve it using self and the scope resolution operator ::.

class One {
 private static $one;
 public static function One() {
  self::$one = something_from_your_db();
 }

 public static function two() {
  do_something(self::$one);
 }
}

Upvotes: 1

Codrutz Codrutz
Codrutz Codrutz

Reputation: 480

Declare $one as a static variable:

private static $one;

And you can access it using : self::$one

Upvotes: 2

Related Questions