• Resolved Gwyneth Llewelyn

    (@gwynethllewelyn)


    This seems to be the worst error that has been plaguing Advertising Manager for many years, and a fix apparently is not likely.

    Basically, creating or editing a new ad fail with an empty page with a cryptic error on the logs, something like this (the error might be different depending on operating system and web server; I’m using nginx on Ubuntu):

    PHP Warning:  Creating default object from empty value in /var/www/clients/client3/web4/web/wp-content/plugins/advertising-manager/lib/Advman/Admin.php on line 55
    PHP Fatal error:  Call to undefined method stdClass::get_network_property_defaults() in /var/www/clients/client3/web4/web/wp-content/plugins/advertising-manager/lib/Advman/Admin.php on line 69
    PHP Warning:  Creating default object from empty value in /var/www/clients/client3/web4/web/wp-content/plugins/advertising-manager/lib/Advman/Admin.php
    PHP Fatal error:  Call to undefined method stdClass::add_revision() in /var/www/clients/client3/web4/web/wp-content/plugins/advertising-manager/lib/OX/Swifty.php

    A possible fix:

    On wp-content/plugins/advertising-manager/lib/Advman/Admin.php, line 54, change:

    if ($value != $ad->name) {
                                                    Advman_Admin::check_default($ad,
                                                    $ad->name = $value;
                                                    $changed = true;
                                            }

    to

    if (property_exists($ad, 'name')) {
                                            if ($value != $ad->name) {
                                                    Advman_Admin::check_default($ad,
                                                    $ad->name = $value;
                                                    $changed = true;
                                            }
                                    }

    On wp-content/plugins/advertising-manager/lib/Advman/Admin.php, line 62, change:

    if ($ad->active != $value) {
                                                    $ad->active = $value;
                                                    $changed = true;
                                            }

    to:

    if (property_exists($ad, 'active')) {
                                            if ($ad->active != $value) {
                                                    $ad->active = $value;
                                                    $changed = true;
                                            }
                                    }

    On wp-content/plugins/advertising-manager/lib/Advman/Admin.php, line 69, change:

    $properties = $ad->get_network_property_defaults();

    to

    if (property_exists($ad, 'get_network_property_defaults')) {
                            $properties = $ad->get_network_property_defaults();
                    }
                    else {
                            $properties = array();
                    }

    On /wp-content/plugins/advertising-manager/lib/OX/Swifty.php, line 102, change:

    $ad->add_revision();
                            return $this->dal->update_ad($ad);

    to:

    if (property_exists($ad, 'add_revision')) {
                            $ad->add_revision();
                            return $this->dal->update_ad($ad);
                    }
                    else {
                            return NULL;
                    }

    This stops the errors, but it also means that the changes do not get saved.

    For four years this problem has been plaguing many users. I <i>think</i> that the problem is with versions of PHP 5.4 or newer (I’m using 5.5), where calling things by reference have been seriously restricted. Thus, what seems to happen is that $ad is empty at some point, and, when passing it as a reference, a new, standard object is created, which of course has all the methods inside it missing. Then everything else fails.

    I’ve done a bit of testing. On Admin.php, inside process(), at some point we have the following code:

    // For operations on a single ad
                    if (is_numeric($target)) {
                            $id = intval($target);
                            $ad = $advman_engine->getAd($id);
                    }

    So technically this should return $ad as an object of the appropriate class. When creating/editing an ad, I’ve tested, and this returns an empty object. No wonder everything fails from then on.

    Putting the following code immediately after the function declaration for save_properties:

    function save_properties(&$ad, $default = false)
            {
                    global $advman_engine;
    
                    if (empty($ad))
                    {
                    ?>
                    <div class="error">
                      <p>
                          <strong>Error: </strong>$ad is empty!
                      </p>
                    </div>
                    <?php
                    }

    will always print the error.

    The code is a bit obscure for me to follow. Apparently, $advman_engine is an object of class OX_Swifty, instantiated as Advman_Dal. getAd() is a method which points to select_ad() in Swifty.php. This, in turn, calls dal->select_ad() which is a method declared in Dal.php… which is empty!

    An obscure reference made in 2010 (!) points to a fix to be done on lib/OX/Ad.php on line 168. Sadly, the domain where this blog used to be hosted is down (and has been down probably for years). Because the owner of that domain prevented this site to be crawled, Google doesn’t have a cached copy of it, and neither has Archive.org. Whatever the fix was, it is now gone forever.

    Looking at lib/OX/Ad.php, line 168 is not especially obvious. It points to the middle of the property extraction process (searching for tags). It’s possible that Ad.php was quite different in 2010, when that bug was fixed. I looked a bit around that block of code to see if something is obviously wrong, but I couldn’t find anything. However, I found something which might get a clue. In some rare occasions, I can create a new ad. But when editing it and saving it, no changes are made. This tends to point to some error when saving/serializing properties.

    Anyway, I’m stumped. The developer has said that he’s back, and updating this plugin’s code. I hope he reads this and tests it out on a more recent version of PHP. I’m pretty sure it worked fine under PHP 5.3, and that strongly hints at a problem in passing things by reference…

    https://www.ads-software.com/plugins/advertising-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author switzer

    (@switzer)

    Hi Gwyneth,

    I have identified this issue and have made a fix. An update will come today. Thanks for letting me know.

    Cheers,
    Scott

    Plugin Author switzer

    (@switzer)

    FYI – v3.4.22 is now live

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Aw thanks, @switzer! I had already abandoned all hope, lol

    I can confirm that your fix works flawlessly for me. I got some 500 errors on the first time I clicked on the ‘Ads’ button, but after a few refreshes, it all worked perfectly again. I guess that Advertising Manager needed to retrieve and save all properties again with your new code. But it is certainly working now — I already managed to add new ads and edit some old ones, all saved perfectly.

    Nice work, and thanks so much for looking into this!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fatal error: Call to undefined method stdClass::get_network_property_defaults()’ is closed to new replies.