'Php, include 2 files with functions "cannot redeclare"
I have two systems in my websites: Wordpress and myBB forum. I want to connect them, everyone who register in wordpress (my main site) will be registered in myBB.
I started to write plugin that will be bridge. and i have the global file of myBB, when I include this file i see this error:
Fatal error: Cannot redeclare get_attachment_icon() ...
Now, how can I include the file but keep the functions seperate? can I include the functions into namespace or variable?
Thanks for help!
Solution 1:[1]
You could:
- Create a class and turn this functions in static methods
- Rewrite the name of the functions and refactor the code
- Or you can try this answer: https://stackoverflow.com/a/23426311/1906372
Solution 2:[2]
Is the function get_attachment_icon really declared in both WP and MyBB? It seems unlikely somehow.
If it is in a single file, then that file has to be included or required with include_once or require_once, not with include or require.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fabiano Araujo |
| Solution 2 | LSerni |
