doujiao1984 2016-07-14 07:35
浏览 13

PHP - 函数[重复]

This question already has an answer here:

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**)
</div>
  • 写回答

1条回答 默认 最新

  • douti0687 2016-07-14 07:43
    关注
        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

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)