Reputation: 37
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
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
Reputation: 480
Declare $one as a static variable:
private static $one;
And you can access it using : self::$one
Upvotes: 2