As you can't have an array in a define or a class constant I thought I'd create an abstract class for configuration data for my project that needs to be more structures than simple values.
At first I thought I'd try something like the following, but this resulted in a syntax error on line 6:
<?php
abstract class Config
{
static private
$paths = array (
'classes' . _DS . 'cmsItems',
'classes' . _DS . 'dbdrivers',
'classes' . _DS . 'core'
);
static public function getPaths ()
{
return self::$paths;
}
}
?>
I then tried defining a static array inside the getter instead of a private property.
<?php
abstract class Config
{
static public function getPaths ()
{
static $paths = array (
'classes' . _DS . 'cmsItems',
'classes' . _DS . 'dbdrivers',
'classes' . _DS . 'core'
);
return $paths;
}
}
?>
This just resulted in a syntax error on line 7
But if I removed the static keyword...
<?php
abstract class Config
{
static public function getPaths ()
{
$paths = array (
'classes' . _DS . 'cmsItems',
'classes' . _DS . 'dbdrivers',
'classes' . _DS . 'core'
);
return $paths;
}
}
?>
This seems to work fine (except now the array is created every time the function runs, which seems a bit wasteful to me).
Can anybody explain what's going on here?
(FYI, _DS is defined elsewhere and is simply an alias to DIRECTORY_SEPARATOR)