-3

I have two files (Ex-one.php,two.php). Some functions have same name in two files. A have another class file. I include that file(one.php,two.php) in two functions on class file. Then I create a object from class file in main php file. Then i call two functions in object(call functions in class file). when I call the function second time error occur ("Cannot function_name() (previously declared in **Previase include file name **")

how I Solve this issue

one.php

function a(){
   }
   function d(){}

two.php

    function a(){
  }
  function d(){}

class file -----------

   class test{

 function one(){
  include_once("one.php")
 }

 function two(){
   include_once("two.php")
 }

}

main file ---------

    $test=new test();
$test->one();

$test->two();//(**in this line error occur**)
2
  • Namespaces if using a newer version of php Commented Jul 14, 2016 at 7:37
  • 1
    You cannot have two functions of the same name and load them both, period. Rename one of them. Using namespaces helps here. Commented Jul 14, 2016 at 7:39

1 Answer 1

0
    namespace xxx {
         function A {}
    }
    namespace yyy{
         function A{}
    }

Not in the same file ofcourse. then to call them include and use \xxx\A

Php.net: Namespaces

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.