Does the Object of PHP point to the same memory address?

like js, is the memory address referenced by Object the same no matter how it is assigned?

Php
Mar.02,2021

Yes

$a = new stdClass();
$b = $a;
$b->x = 1;
$c = clone $a;

xdebug_debug_zval("a");
xdebug_debug_zval("b");
xdebug_debug_zval("c");

a:
(refcount=2, is_ref=0)
object(stdClass)[1]
  public 'x' => (refcount=0, is_ref=0)int 1
b:
(refcount=2, is_ref=0)
object(stdClass)[1]
  public 'x' => (refcount=0, is_ref=0)int 1
c:
(refcount=1, is_ref=0)
object(stdClass)[2]
  public 'x' => (refcount=0, is_ref=0)int 1
The reference count of

an and b is 2, and the two variables point to the same content. When adding attributes to b, both an and b will be changed at the same time, and the new object whose
c is clone $a will not be forcibly split, pointing to the new memory address

.
Menu