0

I have 3 php file index.php file contain following code

<?php
include ('file1.php');
include ('file2.php')
?>

file1.php contain

function aa(){
    sleep(5);
    return 2;
}
function bb(){
    sleep(5);
    return 1;
}
echo bb();
echo aa();
setStartTrigger($AutoID,3,$db_automation);

file2.php contain same function

function aa(){
    sleep(5);
    return 2;
}
function bb(){
    sleep(5);
    return 1;
}
echo bb();
echo aa();
setStartTrigger($AutoID,3,$db_automation);

the output return error

Fatal error: Cannot redeclare aa() (previously declared in C:\xampp\htdocs\automation_kickoff\file2.php:3) in C:\xampp\htdocs\automation_kickoff\file1.php on line 5

i want something without changing any of my function name

Amarendra Kumar
  • 858
  • 9
  • 16
Shimul Chowdhury
  • 103
  • 2
  • 13

1 Answers1

1

You can use Namespaces starting from PHP 5.3.

file2.php

namespace A;

function aa(){
    sleep(5);
    return 2;
}
function bb(){
    sleep(5);
    return 1;
}

namespace {
    echo A\bb();
    echo A\aa();

    setStartTrigger($AutoID,3,$db_automation);
}

and file2.php

namespace B;

function aa(){
    sleep(5);
    return 2;
}
function bb(){
    sleep(5);
    return 1;
}

namespace {
    echo B\bb();
    echo B\aa();

    setStartTrigger($AutoID,3,$db_automation);
}
u-nik
  • 488
  • 4
  • 12