Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Need some help in PHP (https://www.warriorforum.com/programming/436733-need-some-help-php.html)

monicac 21st August 2011 02:23 AM

Need some help in PHP
 
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

SebastianJ 21st August 2011 03:42 AM

Re: Need some help in PHP
 
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.

edynas 22nd August 2011 02:36 PM

Re: Need some help in PHP
 
Quote:

Originally Posted by k3rtiichow (Post 4511265)
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

wayfarer 22nd August 2011 05:16 PM

Re: Need some help in PHP
 
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.


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