Re: New function proposal: spl_object_id

From: Date: Fri, 23 Jan 2009 18:23:07 +0000
Subject: Re: New function proposal: spl_object_id
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-42798@lists.php.net to get a copy of this message
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

« previous php.internals (#42798) next »