{"id":8969326,"date":"2017-03-29T11:58:13","date_gmt":"2017-03-29T11:58:13","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/undefined-variable-errors-2\/"},"modified":"2017-03-29T11:58:13","modified_gmt":"2017-03-29T11:58:13","slug":"undefined-variable-errors-2","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/undefined-variable-errors-2\/","title":{"rendered":"Undefined variable errors"},"content":{"rendered":"<p>Hello there<\/p>\n<p>We are using 3.0.0 version of the plugin, and we are getting a lot of these errors <\/p>\n<pre><code>NOTICE: PHP message: PHP Notice:  Undefined variable: toolObject in wp-content\/plugins\/addthis-all\/backend\/AddThisPlugin.php on line 1433\n\nNOTICE: PHP message: PHP Notice:  Trying to get property of non-object in wp-content\/plugins\/addthis-all\/backend\/AddThisPlugin.php on line 1433<\/code><\/pre>\n<p>Having a look at the file, we confirm the variable isn&#8217;t defined neither in the method nor in the class.<\/p>\n<p>Looking at the original code, we realize that the shortCode might come from the foreach variable rather than the object property<\/p>\n<pre><code>foreach ($shortCodes as $shortCode =&gt; $callback) {\n    if ($this-&gt;shortcodeExists($toolObject-&gt;shortCode)) {\n        continue;\n    }\n    add_shortcode($shortCode, $callback);\n}<\/code><\/pre>\n<p>We modified the code as follows<\/p>\n<pre><code>foreach ($shortCodes as $shortCode =&gt; $callback) {\n    if ($this-&gt;shortcodeExists($shortCode)) {\n        continue;\n    }\n    add_shortcode($shortCode, $callback);\n}<\/code><\/pre>\n<p>There are no more errors related to the undefined variable, but does it makes sense to you?<\/p>\n<p>PHP version is 5.4.16 and is run using FPM<\/p>\n<p>Thank you in advance<\/p>\n","protected":false},"template":"","class_list":["post-8969326","topic","type-topic","status-publish","hentry","topic-tag-php-error"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8969326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8969326\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8969326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}