Hello

My usage for spl_object_id wouldn't be solved with SplObjectStorage,
here is my current event handler (it uses spl_object_hash)
I still have the plan to replace it with something better but it simply works,
currently it's not possible to "free" an object.

EVENT::register accepts a static class or object instance.


class EVENT {
   private static $events = array();

   public static function register($event, $obj, $method) {
       if (!isset( self::$events[$event])) self::$events[$event] = array();
if (is_object($obj)) {
           $hash = spl_object_hash($obj);
       } else {
           $hash = $obj;
       }
       self::$events[$event][$hash] = array($obj, $method);
   }

   public static function fire($event, &$eventData = null) {
       if (isset(self::$events[$event])) {
           foreach(self::$events[$event] as $callable)
           {
               call_user_func_array($callable, array(&$eventData));
           }
       }
   }
}

So spl_object_id would be a nice...

Best regards
Oskar Eisemuth


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to