I'm trying to write a class that uses its parent's static declared array to add a new value to. Below is kind of a feel of how I'm trying to run it...
class SuperClass
{
protected static $array_name = array('value1');
}
class SubClass extends SuperClass
{
protected static $array_name = array_push(parent::$array_name, 'value2');
}
Is there any way to properly implement this without a __construct() function?
I'm trying to implement a static working model for the SuperClass and its parents...
I'm not entirely sure if you want static classes completely, but this does what you want give or take :
<?php
class SuperClass
{
static $array_name = array('value1');
}
class SubClass extends SuperClass
{
static $array_name = 'foo';
function __construct(){
self::$array_name = array_push(parent::$array_name, 'value2');
}
}
$foo = new SubClass();
var_dump($foo::$array_name); // prints INT 2 - as push returns number of elements in array.
?>