Skip to content
doubtly

2 answers

Answer: WordPress runs on PHP (version 5 and later), where objects are passed by handle: the handle is copied by value, but it points to the same object, so in practice objects behave as if passed by reference.

function change($o) {
    $o->x = 2;           // changes the caller's object
    $o = new stdClass;   // only changes the local copy
    $o->x = 3;
}
$p = new stdClass;
$p->x = 1;
change($p);
echo $p->x;   // 2
  • Changing a property inside the function changes the original object, because both variables refer to the same object.
  • Assigning a new object to the parameter does not affect the caller, because only the handle was copied.
  • Arrays and simple values (int, string) are passed by value (copied) unless you use &. To get an independent copy of an object, use clone.
Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.