Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Accessing observer variable externally

    I have an observer class that contains variables that for the most part are used internally; however, I would like to access one of the variables after the notifier event has triggered the observer, but I don't see how the internal data/functions can be accessed if a separate variable hasn't been uniquely declared to be that class type. (Somewhat trying to figure out what variable can be accessed to access the data of the observer.)

    So for example if I have the following observer that is called by an appropriate config file:

    Code:
    class observer_class_to_test extends base {
    
      private $_val = false;
      
      function __construct() {
         global $zco_notifier;
        
         $attachNotifier = array();
         $attachNotifier[] = 'NOTIFY_ME_WHEN_THIS_NOTIFIER_ACTIVATES';
        
         $zco_notifier->attach($this, $attachNotifier); 
      }    
    
      function updateNotifyMeWhenThisNotifierActivates(&$callingClass, $notifier, $paramsArray){
        global $some_value;
    
        if ([condition_is_true]) {
         $this->_val = true;
        }
      }
    }
    What I would like to do is elsewhere in the "main" body I would like to retrieve the condition of $_val as it relates to the above class/function. I've found that I could "create" a variable by establishing a variable as global and then setting that global variable equal to the internal variable... This directly "transfers" it to the global side of data; however, I'm trying to see if there is an alternative method of accessing the internal data through some other method. Seems that even if an accessor function were developed there would still need to be something to reference to activate the function... I do (now) recognize that the data was declared private, so I plan to test with that set as public to see if I can find a way to access it while awaiting a kind individual that may have figured this out to post...

    I've generically provided information associated with the conditions as an example of structure rather than specific function...
    Last edited by mc12345678; 11 Oct 2015 at 12:04 AM. Reason: Realized that variable is private, going to try making public and repeating test(s)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default Re: Accessing observer variable externally

    You could add a function to return the private value. Once your observer class is instantiated, its data/class-functions can be accessed using its instantiated name.

    Note also that you don't need the $zco_notifier object. Since your observer class extends the base, it's got its own attach function.
    Code:
    class observer_class_to_test extends base {
    
      private $_val = false;
      
      function __construct() {
         $attachNotifier = array();
         $attachNotifier[] = 'NOTIFY_ME_WHEN_THIS_NOTIFIER_ACTIVATES';
        
         $this->attach($this, $attachNotifier); 
      }    
    
      function updateNotifyMeWhenThisNotifierActivates(&$callingClass, $notifier, $paramsArray){
        global $some_value;
    
        if ([condition_is_true]) {
         $this->_val = true;
        }
      }
    
      function get_the_var () {
        return $this->_val;
      }
    }

 

 

Similar Threads

  1. v154 Naming a global variable the same as a SESSION, GET or POST variable
    By torvista in forum General Questions
    Replies: 5
    Last Post: 6 Dec 2015, 11:11 AM
  2. Replies: 8
    Last Post: 10 Jan 2010, 08:04 PM
  3. Replies: 0
    Last Post: 5 Nov 2009, 04:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR