![]() |
Help with conflicting function names
I've made my site, but I'm trying to integrate MyBB in as well. Problem is, they use the function redirect() and add_breadcrumb(), and so do I. When I include my header file into MyBB (to get the user info or whatever) it includes my function file, which then gives me a 'cannot redeclare' etc.
Is there a way to either overwrite or 'cancel out' my functions? I don't really want to have to fundamentally change the entire codebase especially since things like redirect() are pretty common names. I've looked into namespaces but don't know if they're perfect for my problem. I'm also only using PHP 5.2.5 at the moment so I don't think they're available. Any options? :-( |
Now, I don't know how your Site structure looks like, but when you want to "cancel out" your functions you could simply write them in an external file, and just include em when you need them || when you do not include the MyBB functions.
Or you could simply rename your functions? I mean it's not to difficult - just search and replace -> enter the function name like "redirect(" and replace with "own_redirect(" (or some better fitting name ;) ). Not sure wheter there is an simpler method. |
Rename them to less generic names, such general naming indicates a bad general naming schema. You could overload functions (given that they have a different number of arguments) or use namespaces, but both would be bad practice.
|
Quote:
|
Quote:
The primary purpose of namespaces is to avoid loading lots of functions that you do not need, not to resolve ambiguous names (not to say that is doesn't accomplish that, it just shouldn't be used solely for it). |
I always thought it was to resolve ambiguous names, and things like include() and require() were used to avoid loading lots of functions that you do not need.
PHP Code:
|
Sakakuchi, I basically just include all of my functions and then included it at the top of MyBB as well, since it didn't make sense at this point to split up my functions.
I gave in and renamed them at least to do_breadcrumb and location() |
Quote:
While it does work for resulving ambigous names, your functions probably should not be named directly after language level functions. |
Ah see I've never used namespaces before, I adhere to my own naming conventions that have thus far gotten me by without want. I doubt I'll ever have the gumption to tackle C++ either, what with PHP by itself making me all warm and fuzzy inside. :D
|
| All times are GMT. The time now is 01:08 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0