0

I have the following error when executing this part of the code:

Cannot redeclare wfColoridoRender() (previously declared in /data/web/a1/eb/4e/.../htdocs/wiki/extensions/Colorido/Colorido.class.php:9) in /data/web/a1/eb/4e/.../htdocs/wiki/extensions/Colorido/Colorido.class.php on line 9

What is the problem in this code? I do not understand what is wrong

the code complete:

<?php
 
$wgHooks['ParserFirstCallInit'][] = 'onParserFirstCallInit';

function onParserFirstCallInit( Parser $parser ) {
    $parser->setHook( 'colorido', 'wfColoridoRender' );
}

include_once wfColoridoRender( $input, $argv, $parser ) { 
 
    // Character styles
    $input = utf8_decode($input);
    $output = ""; // To stop the "Undefined Variable" errors in the webserver logfile
 
    for ($i = 0; $i < strlen($input); $i++)
      {
    $s = rand(0, 9) * 8 + 150;
    $w = rand(5, 9) * 100;
    $r = rand(20, 230);
    $g = rand(20, 230);
    $b = rand(20, 230);
 
    $output .= 
      '<span style="font-size: ' . strval($s) . '%; font-weight:' 
      . strval($w) . ';color: #' . dechex($r) . dechex($g) . dechex($b) 
      . ';">';
 
    $output .= $input[$i];
    $output .= '</span>';
      }
      
    return utf8_encode($output);
};
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • The problem is that your script contains the same function twice. Either you've actually got the same function name twice in two different places, or you've accidentally included/required the file which contains that function more than once into your main script. Judging by the error message pointing to the same file and line twice I'd say its probably the latter. Always use `include_once` / `require_once` rather than `include` / `require` – ADyson Sep 30 '21 at 22:54
  • it seems that using those functions marks another error syntax error, unexpected ';' – La rama azul Sep 30 '21 at 23:09
  • Which of those lines does the error point to? Or if it's a line you haven't shown, please edit your question to include it (and the lines nearby). Please also refer to https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them for guidance – ADyson Sep 30 '21 at 23:11
  • from /data/web/a1/eb/4e/.../htdocs/wiki/extensions/Colorido/Colorido.class.php(12) – La rama azul Sep 30 '21 at 23:12
  • this is the section: $input = utf8_decode($input); – La rama azul Sep 30 '21 at 23:12
  • I don't know which is your line 12, I cannot see your line numbers. Please edit the question to include relevant code and indicate which line the error message points to. Also include nearby lines please, as these kinds of syntax errors are often a combination of problems on different lines – ADyson Sep 30 '21 at 23:13
  • Well the complete code is already published – La rama azul Sep 30 '21 at 23:31
  • That is not how you use `include_once`, what you have done makes no sense. Please read the manual for that function so you understand what it is for. I was suggesting you replace an instance of `include` with `include_once`...it makes no sense to replace `function` with `include_once`...what did you think it would do? – ADyson Sep 30 '21 at 23:34
  • Well, I thought that because the `wfColoridoRender` function was repeated, the `include_once` variable could replace it and solve the problem but it seems that it is not like that and then for that reason I don't know how to do it. – La rama azul Sep 30 '21 at 23:40
  • I've already told you what to do. Look for `include` and `require` commands throughout your code and replace them with `include_once` and `require_once`. This will ensure that even if you have accidentally included the same file twice in your script, PHP will ignore the request the second time – ADyson Oct 01 '21 at 05:42

0 Answers0