Unique()?
Bastien
Sent from my iPod
On Jan 10, 2009, at 6:31 PM, Nathan Rixham <nrixham@xxxxxxxxx> wrote:
Evening All,
Not too often I ask a question here, but here goes;
I'm making an "Object" class which all of my other classes extend,
and I need each instance to have it's own unique id, seemed simple
but it's harder than I thought (the difficulty is when it comes to
deciding the syntax).
so far each object has an OBJECT_ID which is a simple static
incremented integer representing the instance of the object, here's
a simplified example:
abstract class Object {
private static $INSTANCES = 0;
private $OBJECT_ID = 0;
public function __construct()
{
$this->OBJECT_ID = ++self::$INSTANCES;
}
}
Now back to the problem, I also need the object to have
private $UNIQUE_ID;
this unique_id needs to have:
timestamp
classname
object_id
combining the three makes a unique id; but it's only unique to that
session, no good for a real world application as there could be 50
sessions all running at the same time on the server; and odds are
rather high that two instances of the object could have the same id.
Thus an extra completely unique identified needs added to the three
values above.
I'd thought a simple random integer would possibly be enough
(combined with the timestamp), but there could still be collission.
so the best I've got so far is:
[OBJECT_ID:private] => 3
[UNIQUE_ID:private] => instance://1231629807@xxxxxxxxxxxx:97739
timestamp @ class . instance : randomInteger
all I need is a completely unique id for each object instance that
can never be repeated at any time, even in a multiserver environment
(and without using any kind of incremented value from a db table or
third party app)
thoughts, ideas, recommendations?
regards!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php