views:

126

answers:

1

EDIT: Language is PHP. So, I'm implementing a listener/observer pattern. One of the objects I implemented was an object for including files. Which works in a way like this:

class IncludeEvent extends Event {
   protected $File = '';
   public $Contents;
        ....
   public function Begin() {
        ....
        // this is the ONLY time $Contents is modified:
        $this->Contents = ob_get_contents();
        ob_end_clean();
        ....
   }
        ....
   if ($this->Notify(new IncludeObject($this->File,'OBOutput', $this)) !== false) {
        print $this->Contents;
   }
}

Now, whenever an object wants to signal its listeners that an event happened, they need to use the Notify function. So at one point I had to send a reference to the object to its listeners, so they could have access to the included content ($Contents). So I used Notify() passing $this as the parameter. When I try to access the $Content from the other object, it simply returns as an empty string.

Note: The object functions as it should in a normal context, only when I pass it as a function parameter I can't access its $Content.

The constructor for IncludeObject():

public function __construct($F= '', $M= -1, &$IV = null) {
    $this->File = $F;
    $this->Func = $M;
    $this->IncEv = $IV;
}

The listener accesses the IncludeEvent object like this:

public function OBOutput($IncObj){
    print $IncObj->IncEv->Contents;
    return false;
}

So yeah, how do I access long strings from object references? It works fine with short strings, but something like a long included file just returns empty.

Notify() is defined as:

final public function Notify($EvObj = null) {
        foreach ($this->listen_list as $z) {
            $d = call_user_func(array($z, $EvObj->Func), $EvObj);
            if ($d == true || is_null($d)) {
                return true;
            }
        }
        return false;
    }
A: 

how do I access long strings from object references? It works fine with short strings, but something like a long included file just returns empty.

you're barking up the wrong tree. and btw, you don't need that & at all. objects are passed by reference without it (not in PHP 4, but you shouldn't be using that nowadays).

just somebody
Yep, I have no idea what part of it is wrong. That's pretty much what I want to know.
knuck
my guess is that your `IncludeEvent::Begin` method (where the `Content` member is set) is not called. oh, and again: **you don't need that ampersand**. objects are **always** passed by reference.
just somebody