I write a wordpress plugin. My plugin code in inside a class.
if (!class_exists("Pluginname")) {
class Pluginname {
...
}
}
if (class_exists("Pluginname")) {
$obj = new Pluginname;
}
Question: What if $obj
is already used in WordPress code or in another plugin? Can this be a potential source of conflict? If so, what to do?
They can. Say you have plugin one, with only this:
And then you have plugin two, with only this:
And now you activate these plugins, you will probably see the variable of plugin one echo’d by plugin two (at least it did here, but I don’t know what determines the sequence).
It’s probably best to use a sort of prefix like $my_plugin_variable if you’re not using it inside a function or class.