What is the correct way in writing arrays in config.sample.php

Original (closed) core issue 31122

This is a generic question I want to address.

What is the correct respectively preferred way in writing arrays in config.sample.php Based on this result, I would like to harmonize all arrays in config.sample.php to the same layout and file a documentation PR in the development guide with the definition made.

The documentation gives no statement about this and from phpcs I cant read it out.
I am clearly focussing on config.sample.php not in how arrays should be written in the code. As you see in the examples of this file, we have many variants of valid php array styles present. My attempt is finding / define a preferred way, harmonize the array in the file to this definition and document the way how an array should be used for this file in the developer guide.

The freedom of beeing able to use all array styles available in php in config.sample.php - even all work - doesn´t not look good nor looks professional but confusing. I am absolutely convinced that a guideline and its usage/expression in config.sample.php is necessary and a good thing.

I am fine with any definition made, but there has to be one.

I would like have a statement for:
- single array: [ ] vs array ( )
- array in array
- do we need to write array keys 0 => vs 'list of items'
- are there php version dependencies (just to be sure)

Currently we have following variants present:
1. Square bracket
=> [ ]
2. The term array with round brackets

  array (
    'demo.example.org',
    'otherdomain.example.org',
  ),

3. The term array in term array with round brackets, sub array key is defined

=> array(
	array(
		'class' => 'OC_User_IMAP',
		'arguments' => array('{imap.gmail.com:993/imap/ssl}INBOX')
	)

4. Array in array with square brackets, sub key is defined, sub array value is in square brackets

[
        [
		'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9',
		'users' => ['user1'],
		'apps' => ['files_texteditor'],
		'logfile' => '/tmp/test.log'
        ],
        [

5. The term array in term array with round brackets, array key is a counting number

=> 
    array (
      0 => 
      array (
        'path' => OC::$SERVERROOT.'/apps',
        'url' => '/apps',
        'writable' => 'false',
      ),
      1 => 
      array (

6. Array in array with square brackets, sub key is defined, one sub array has more values without brackets, comma seperated

=> [
	'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required
		'localhost:7000',
		'localhost:7001'
	],
	'timeout' => 0.0,
	'read_timeout' => 0.0,
	'failover_mode' => \RedisCluster::FAILOVER_DISTRIBUTE

@PVince81, @DeepDiver1975

in config.php I'd expect all arrays to use square brackets and no array indices

The reason why they appear as such is only a bug in the config serializer that writes back the config into config.php and seems to not be able to use this format. Maybe the serializer can be told to use this format ?

So we have two things.
1.) the serializer where ownCloud writes a config entry to config.php
2.) manually added entries which are documented in config.sample.php

Even if the serializer cant write square brackets, this could be documented and 2 is a rule for contributers when creating new keys containing arrays which also needs documentation in the dev guide and config.sample.php

The code for writing an array to config.php can be found in:

lib/private/Config.php#L109
public function setValues(array $configs) {

Just did a test,
when defining an array with square brackets like

$defaultAppsPaths = [
					'apps_paths' => [
						[
							"path" => $appsDir,
							"url" => "/apps",
							"writable" => false
						],
						[
							"path" => $appsExDir,
							"url" => "/apps-external",
							"writable" => true
						]
					]
];
$config->setSystemValues($defaultAppsPaths);

this array is written to config.php in the style of:

  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/owncloud/core/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/owncloud/core/apps-external',
      'url' => '/apps-external',
      'writable' => true,
    ),
  ),