Re: [PHP] Unique Object Instance ID..?



On Sat, 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



I was going to say uuid, but maybe SplObjectStorage might be of some help.
.



Relevant Pages

  • Re: [PHP] Unique Object Instance ID..?
    ... private static $INSTANCES = 0; ... 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. ... I'd thought a simple random integer would possibly be enough (combined with the timestamp), but there could still be collission. ...
    (php.general)
  • Unique Object Instance ID..?
    ... private static $INSTANCES = 0; ... 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. ... I'd thought a simple random integer would possibly be enough (combined with the timestamp), but there could still be collission. ...
    (php.general)
  • Re: OOP in ASP .Net Pages
    ... Is there a Static type modifier that is session specific. ... Private m_OfficeID As System.String ... Public Property CompanyID() As System.String ... Public Sub New ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Fragmentation Elimination Problem
    ... timestamp = datetimehour to hour ... look in the relative fragments. ...
    (comp.databases.informix)
  • Re: Who is blocking the record I want to edit?
    ... to issue your DML statement against the record in question. ... Add an update timestamp column to your records so that any time ... User edits record on your application ... session waits for another session until commit or rollback. ...
    (comp.databases.oracle.misc)