Sidebars examples
Static_class.php
Code
<?php
class Test {
static protected array $test = array();
protected $words = array();
public static function addWord($word)
{
self::$test[] = $word;
}
public function __construct()
{
$this->words = array_map(
fn ($array) => $array, self::$test
);
}
public function showWords()
{
foreach ($this->words as $w) {
echo $w . '<br />';
}
}
}
Test::addWord('test');
$t = new Test;
$t->showWords();
Test::addWord('test 2');
echo '<br />';
$t = new Test;
$t->showWords();
?> Output
test
test
test 2
test
test 2