Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Aug 2011, 02:23 AM   #1
PHP Geek :)
War Room Member
 
monicac's Avatar
 
Join Date: 2010
Location: Montreux, Switzerland
Posts: 89
Thanks: 41
Thanked 14 Times in 14 Posts
Default
Need some help in PHP
Share on: 
fb share twitter share gplus share more share

I am coding a wp plugin and when I am trying to use a library it is saying that some other plugin has declared that library and so I cannot redeclare that thing..

So i was jus wondering what needs to be done to overcome this problem....I can manage to play with this plugins but was just wondering how to approach this problem if I am gonna sell this plugin...I cannot ask my clients to uninstall some other plugin to get my plugin working so...

Any help would be really appreciated
monicac is offline  
Unread 21st Aug 2011, 03:42 AM   #2
Active Warrior
 
SebastianJ's Avatar
 
Join Date: 2007
Location: Sweden
Posts: 84
Thanks: 7
Thanked 11 Times in 11 Posts
Default
Re: Need some help in PHP
Share on: 
fb share twitter share gplus share more share

I had this exact same problem when I started developing my auto-blogging plugin Roboblogger .

Here's how I solved it:
Code:
if (!class_exists('Smarty')) //Template Engine
{
  require_once(dirname(__FILE__) . '/vendor/plugins/Smarty-3.0.7/libs/Smarty.class.php');
}
The only thing I haven't figured out yet is how to make this work with specific versions (e.g. if another plugin uses Smarty 3.0.2 and I need at least Smarty 3.0.7). I haven't really had a need for this yet, so I'll guess I'll figure it out when I bump into this issue.
SebastianJ is offline  
Unread 22nd Aug 2011, 02:36 PM   #3
Banned
War Room Member
 
Join Date: 2006
Location: The Hague,Netherlands.
Posts: 1,077
Thanks: 384
Thanked 220 Times in 136 Posts
Blog Entries: 1
Default
Re: Need some help in PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by k3rtiichow View Post

I am coding a wp plugin and when I am trying to use a library it is saying that some other plugin has declared that library and so I cannot redeclare that thing..

So i was jus wondering what needs to be done to overcome this problem....I can manage to play with this plugins but was just wondering how to approach this problem if I am gonna sell this plugin...I cannot ask my clients to uninstall some other plugin to get my plugin working so...

Any help would be really appreciated
Easiest way....Rename it
Or you can rely on the class/functins already loaded and if it's a very common thing then that would be probibly best but if it's not it holds the risk that it's modified by the other developer and will not do what you expect it to do.

I always have the names of my classes and functions started with the name of my plugin to make sure it won't clash with others and to overcome issues like these

HtH
Edwin
edynas is offline  
Unread 22nd Aug 2011, 05:16 PM   #4
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: Need some help in PHP
Share on: 
fb share twitter share gplus share more share

Renaming it could turn out to be a pain in the butt if there's a huge number of classes and/or functions. This is because the functions could use each other internally. If you rename it an it breaks, I would just use the class_exists() or function_exists() method.

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Closed Thread


Bookmarks

Tags
php


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

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




All times are GMT -6. The time now is 12:31 PM.