Nucleus Support Forum Index

Find on the forum:
any terms  all terms  Advanced Search

RSS 2.0
Browse posts: Unanswered | Mark all read

« »
Loading Nucleus FAQ ticker...
Post new topic Reply to topic
Author Message
xiffy
Nucleus Guru
Nucleus Guru


Joined: 27 Mar 2002
Posts: 1218
Location: Deventer

Post Posted: Mon Sep 25, 2006 11:18 pm   Post subject: Backreferntial object not working in some php versions
Reply with quote

I'm using PHP5 on my box and don't have a need for a PHP4 test environment. But this lazyness has off course backfired when developing plugins. In the plugin I instantiate a class like this:
Code:

class NP_Plugin {
    function NP_Plugin() {
        $lib = new LIB($this);
    }
}

class LIB {
    function LIB($parent) {
        $sqllib = new SQLLIB($parent);
    }
}

class SQLLIB {
    function SQLLIB($plugin) {
        $this->plugin = $plugin;
    }
    function somefunction() {
        $value = $this->plugin->getOption('someoption');
    }
}

The problem is of course $value = $this->plugin->getOption('someoption'); in the somefunction inside SQLLIB.
It does not work on some (older?) PHP installs. No error, but no value either
Does anyone know how I can get a plugin option from some distant CLASS that works on all php versions?

cheers

_________________
__deus ex machina__
http://xiffy.nl/weblog/
Japan photo's: http://2006.cooljapan.nl/main.php?g2_itemId=20

Back to top

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger ICQ Number
pepiino
Nucleus Disciple


Joined: 26 Feb 2005
Posts: 100
Location: Czech Republic

Post Posted: Tue Sep 26, 2006 9:08 pm   Post subject: Re: Backreferntial object not working in some php versions
Reply with quote

xiffy wrote:

It does not work on some (older?) PHP installs. No error, but no value either
Does anyone know how I can get a plugin option from some distant CLASS that works on all php versions?


It's a problem of PHP4 and object copying. I'v just sent you a bugreport about NP_SpamBayes and php4 (see http://forum.nucleuscms.org/viewtopic.php?p=67138#67138). It's the same problem you are mentioning here and I included my explanation and solution in the post.

In your example it should be:
Code:

class NP_Plugin {
    function NP_Plugin() {
        $lib = new LIB($this);
    }
}

class LIB {
    function LIB(&$parent) {                   // <====reference operator should be here
        $sqllib = new SQLLIB($parent);
    }
}

class SQLLIB {
    function SQLLIB(&$plugin) {              // <====and here
        $this->plugin = &$plugin;              // <====and here
    }
    function somefunction() {
        $value = $this->plugin->getOption('someoption');
    }
}


Welcome to the PHP4 reference hell Sad

_________________
Josef 'pepiino' Adamcik <jabber:josef.adamcik@jabber.cz>,<GTalk: josef.adamcik@gmail.com>
http://blog.pepiino.info
NP_MiniForum - guestbook or shoutbox for your site!

Back to top

View user's profile Send private message Send e-mail Visit poster's website ICQ Number
xiffy
Nucleus Guru
Nucleus Guru


Joined: 27 Mar 2002
Posts: 1218
Location: Deventer

Post Posted: Tue Sep 26, 2006 9:51 pm   Post subject:
Reply with quote

Okay, that's what I needed.
And yes you guessed right on the other topic Wink

_________________
__deus ex machina__
http://xiffy.nl/weblog/
Japan photo's: http://2006.cooljapan.nl/main.php?g2_itemId=20

Back to top

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger ICQ Number
Post new topic Reply to topic
Display posts from previous:   

Page 1 of 1

All times are GMT + 1 Hour

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group