Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

331
Visualizações
Doxygen and "self" keyword on PHP documentation

I'm tryin to document a my PHP library with doxygen, but I cannot configure it to let recognize the correct usage of member function of my class, using the keyword "self". For instance the following code:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return self::myfunc1(); }
}

is not correctly documented. Doxygen maps the two funcions, but when it refer to the internal or external call to these function, it doesn't take in account the myfunc1 called by myfunc2.

My workaround at the moment is to changed the code as follows:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return myclass::myfunc1(); }
}

In this case doxygen refers correctly to the usage of myfunc1 related to myfunc2. Of course I don't like very much this solution. How can I solve this issue? thank you very much

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Doxygen provides input filter option, which enables us to change the source code at the time of documentation creation. For e.g. It gives us ability to intercept the code and change the code self::myfunc1 to myclass::myfunc1 on fly, which Doxygen understands. It does not change the actual source code in any way.

I have created a filter based on code from Doxygen PHP Filters with some modifications, which can do the changes for you.

Please create a file /path/to/selfFilter.php and put the code inside it:

<?php
//Create file /path/to/selfFilter.php

$source = file_get_contents($argv[1]);
$tokens = token_get_all($source);
$classes = array();
foreach($tokens as $key => $token)
{
    if($token[0] == T_CLASS)
        $classes[] = $tokens[$key+2][1];
}
if(!empty($classes))
{
    list($source, $tail) = explode('class ' . $classes[0], $source, 2);
    $class_code = '';
    for($i = 1; $i < count($classes); $i++)
    {
        list($class_code, $tail) = explode('class ' . $classes[$i], $tail, 2);
        $class_code = preg_replace('#\bself::#', $classes[$i-1].'::', $class_code);
        $source .= 'class ' . $classes[$i-1] . $class_code;
    }
    $class_code = preg_replace('#\bself::#', $classes[count($classes)-1].'::', $tail);
    $source .= 'class ' . $classes[count($classes)-1] . $class_code;

}

echo $source;

Update the following options in your doxygen config file.

INPUT_FILTER           = "php /path/to/selfFilter.php"
FILTER_PATTERNS        = 
FILTER_SOURCE_FILES    = YES
FILTER_SOURCE_PATTERNS =

Please make sure that the /path/to/selfFilter.php is executable and php is available on the path, otherwise use the full php path

INPUT_FILTER           = /usr/bin/php /path/to/selfFilter.php

If you run the Doxygen now it should work. Please let me know if you have any issues.

Note: The keyword 'class' should be defined in lower case for the above filters to work.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda