Question

Since PHP 5.4 there is a short syntax for arrays.
One can write $arr = [1,2,3,4,5]; insted of $arr = array(1,2,3,4,5);

But if you have something like this:

class Test
{
   /**
    * brief description
    * @var array $arr
    */
   $arr = [  0 => [ ... ], 2 => [ ... ]  ];
}

then doxygen does not show an initializer line or only something like [ 0 => [ ... ].

By now I have a lot of code only using the short syntax and I don't want to change this for a documentation tool.

Is there any way to teach doxygen to use [...] as array( ... )? I'm using doxygen 1.8.7

Thanks in advance

EDIT :
I had an idea, that the problem could be a line break, if I write it like this

   $arr = [  0 => [ ... ], 
             2 => [ ... ]  ];

I tested this, but no effect. But if I left out the first comma, it works fine (with and without the line break). But if I left out the comma, it is obviously a syntax error.

Any ideas how to fix this?

Was it helpful?

Solution

It takes a while but I found a way myself. Maybe someone has the same problem, so I post my solution here.

I read this answer to another question and I wrote a filter that changes
public $var = [ ... ]; to public $var = array( ... );

Doxygen than will show the array and everything inside correctly.

<?php 

$source = file_get_contents($argv[1]);

$regexp = '#(var|public|protected|private)\s+(\$[^\s;=]+)\s+\=\s+\[([\s\S]*?)\]\;#';
$replac = '${1} ${2} = array( ${3} );';
$source = preg_replace($regexp, $replac, $source);

echo $source;

?>

Here is a preview of the regex.

You can find some more input filters to improve doxygen's php support on GitHub.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top