URL Friendly: Fatal error: Can not redeclare parse_path ()

1

I have this code in a vars.php document to implement a friendly url:

<?php
//var_dump($_SERVER);
function parse_path() {
    $path = array();
    if (isset($_SERVER['REQUEST_URI'])) {
        $request_path = explode('?', $_SERVER['REQUEST_URI']);

        $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
        $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
        $path['call'] = utf8_decode($path['call_utf8']);
        if ($path['call'] == basename($_SERVER['PHP_SELF'])) {
            $path['call'] = '';
        }
        $path['call_parts'] = explode('/', $path['call']);

        $path['query_utf8'] = urldecode($request_path[1]);
        $path['query'] = utf8_decode(urldecode($request_path[1]));
        $vars = explode('&', $path['query']);
        foreach ($vars as $var) {
          $t = explode('=', $var);
          $path['query_vars'][$t[0]] = $t[1];
        }
    }
    return $path;
}

$path_info = parse_path();
echo '<pre>'.print_r($path_info, true).'</pre>';

?>

<?php
switch($path_info['call_parts'][0]) {
    case 'aempresa': include 'aempresa.php';
        break;
    case 'contato': include 'contato.php';
        break;
    case 'cumeeiras': include 'cumeeiras.php';
        break;
    case 'informacoes-tecnicas': include 'informacoes_tecnicas.php';
        break;
    case 'orcamento': include 'orcamento.php';
        break;
    case 'telha-ondulada-natural': include 'telha_ondulada_natural.php';
        break;
    case 'telha-pre-pintada': include 'telha_pre_pintada.php';
        break;
    case 'telha-termoacustica-semi-sanduiche': include 'telha_termoacustica_semi_sanduiche.php';
        break;
    case 'telha-trapezoidal-natural': include 'telha_trapezoidal_natural.php';
        break;
    case 'telhas-termoacusticas-sanduiche': include 'telhas_termoacusticas_sanduiche.php';
        break;
    case 'vantagens': include 'vantagens.php';
        break;
  default:
    include 'index.php';
}

?>

However, you are printing the following error:

  

Fatal error: Can not redeclare parse_path () (previously declared in /var/www/html/formaremetais.com.br/web/teste/vars.php:4) in /var/www/html/formaremetais.com. br / web / test / vars.php on line 4

Address for review: link

Include code on all pages of the site using require

Note: the site is not separated in includes.

But the above error is occurring.

I need some help to fix this bug and find out what's going on. Thank you.

    
asked by anonymous 25.01.2016 / 15:22

1 answer

4
  

Can not redeclare function NameFunction

The error is very clear, says that the function name was declared two or more times within the same scope in the global case, remember that it is possible to define names of functions alike but in different namespace.

To solve this, check the file mentioned in the error and remove the definition of this function, to improve the organization leave only one file with the creation of functions, do not spread them in different files.

    
25.01.2016 / 15:35