Identity¶
Identity in software has several related but distinct meanings:
Identity function: the function that returns its only argument, without any modification. It is a base for null pattern, and is useful when a callable is required, but should be a no operation.
Object identity: two variables refer to the same object in memory. This is tested with the
===operator on objects, or withspl_object_id(). Two objects may be equal in value but not identical in identity.User identity: the set of attributes that uniquely identify a user or entity in a system: username, email, unique ID. Identity is established by identification and verified by authentication.
Domain identity: in Domain-Driven Design, an entity is defined by its identity rather than its attributes. Two
Userobjects with the same$idare the same entity even if other properties differ, while twoMoneyvalue objects with the same amount are equal without having an identity.
PHP applications manage identity through unique IDs, session tokens, and authentication tokens such as JWTs.
<?php
$a = new stdClass();
$b = $a; // same identity
$c = clone $a; // different identity, same values
var_dump($a === $b); // true — same identity
var_dump($a === $c); // false — different identity
echo spl_object_id($a); // unique integer ID for $a
?>
See also Identity vs Equality in PHP and DDD: Entities vs Value Objects.
Related : Identification, Authentication, Identity Comparison, JSON Web Token (JWT), Universally Unique IDentifier (UUID), Object, Clone, Domain Design Driven (DDD), Noop, Callables, Functions, Noop