Static properties in classes
The snippet can be accessed without any authentication.
Authored by
Thomas Flori
Edited
<?php
class Anything
{
public static $current = 'initial value';
protected $value;
/**
* Anything constructor.
*
* @param $value
*/
public function __construct($value)
{
$this->value = $value;
}
public function select()
{
self::$current = $this->value;
}
}
var_dump(Anything::$current);
$o1 = new Anything('object 1');
$o2 = new Anything('object 2');
$o1->select();
var_dump($o1::$current);
$o2->select();
var_dump($o1::$current);
Please register or sign in to comment