TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-16-2009, 06:34 AM   #1 (permalink)
The Wanderer
 
lucid's Avatar
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
lucid is on a distinguished road
Default 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?
lucid is offline  
Reply With Quote
Old 03-16-2009, 07:24 AM   #2 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

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.

Last edited by Sakakuchi : 03-16-2009 at 10:04 AM.
Sakakuchi is offline  
Reply With Quote
Old 03-16-2009, 05:40 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
Old 03-16-2009, 06:05 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
namespaces [snip] would be bad practice.
Say what?!
Salathe is offline  
Reply With Quote
Old 03-16-2009, 06:25 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Say what?!
For the purpose described, using namespaces is probably not the best way to solve a naming conflict.

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).
__________________

Village Idiot is offline  
Reply With Quote
Old 03-16-2009, 07:55 PM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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:
$user_registration = new user::register;
$new_session = new session::register;

$mybb = new mybb::redirect;
$lucid = new lucid::redirect
Seems namespaces would be the perfect alternative to search and replace?
delayedinsanity is offline  
Reply With Quote
Old 03-16-2009, 09:11 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
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:
$user_registration = new user::register;
$new_session = new session::register;

$mybb = new mybb::redirect;
$lucid = new lucid::redirect
Seems namespaces would be the perfect alternative to search and replace?
Coming from a C++ brackground, that is not the case. In C++, many standard includes (Iostream for example) have hundreds of functions covering both in and out functions. When you just want to output data without loading the cIn functions, you write the command "std::cout << "text""

While it does work for resulving ambigous names, your functions probably should not be named directly after language level functions.
__________________

Village Idiot is offline  
Reply With Quote
Old 03-16-2009, 08:14 PM   #8 (permalink)
The Wanderer
 
lucid's Avatar
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
lucid is on a distinguished road
Default

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()
lucid is offline  
Reply With Quote
Old 03-17-2009, 01:13 AM   #9 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
The hello world contest Village Idiot The Lounge 9 01-07-2008 02:15 PM


All times are GMT. The time now is 03:20 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design