note 129140 added to function.spl-object-id

From: Date: Thu, 04 Jan 2024 10:23:00 +0000
Subject: note 129140 added to function.spl-object-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-221094@lists.php.net to get a copy of this message
As an example of when this function might be useful: <?php class Person { function __construct(public string $name) {} } class Group { function __construct(public string $name) {} } // These are three people and a group, some of them share the same attributes. $anna = new Person('Anna'); $bob = new Person('Bob'); $bobGroup = new Group('Bob'); $otherBob = new Person('Bob'); // Checking if the objects are the same returns true if the objects are of the same class and have the same attributes. var_export($anna == $bob); // false var_export($bobGroup == $bob); // false var_export($bob == $bob); // true var_export($otherBob == $bob); // true (even though they're different objects) // Different objects receive a different ID, even if they're of the same class and have the same attributes! var_export(spl_object_id($anna) == spl_object_id($bob)); // false var_export(spl_object_id($bobGroup) == spl_object_id($bob)); // false var_export(spl_object_id($bob) == spl_object_id($bob)); // true var_export(spl_object_id($otherBob) == spl_object_id($bob)); // false :D ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2a02:a449:c7a9:0:60eb:5c69:e2:30de) ---- Manual Page -- https://php.net/manual/en/function.spl-object-id.php Edit -- https://main.php.net/note/edit/129140 Del: integrated -- https://main.php.net/note/delete/129140/integrated Del: useless -- https://main.php.net/note/delete/129140/useless Del: bad code -- https://main.php.net/note/delete/129140/bad+code Del: spam -- https://main.php.net/note/delete/129140/spam Del: non-english -- https://main.php.net/note/delete/129140/non-english Del: in docs -- https://main.php.net/note/delete/129140/in+docs Del: other reasons-- https://main.php.net/note/delete/129140 Reject -- https://main.php.net/note/reject/129140 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221094) next »