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?

1 Answer
1

They can. Say you have plugin one, with only this:

// Plugin one
$variable = "henk";

And then you have plugin two, with only this:

// Plugin two
echo $variable;

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *