Skip to content

Instantly share code, notes, and snippets.

@giorgiosironi
Created July 4, 2011 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giorgiosironi/1063267 to your computer and use it in GitHub Desktop.
Save giorgiosironi/1063267 to your computer and use it in GitHub Desktop.
function doSomethingRef(&$o) {
$o = null;
}
function doSomething($o) {
$o = null;
}
$object = new stdClass;
// passed by reference
doSomethingRef($object); // $object is now null
// passed by handler (usual case)
doSomething($object); // $object is still a stdClass
@fprochazka
Copy link

That's a little bit confusing, isn't it? Shouldn't it be more like:

$object = new stdClass;
// passed by reference
doSomethingRef($object); // $object is now null

$object = new stdClass;
// passed by handler (usual case)
doSomething($object); // $object is still a stdClass

@giorgiosironi
Copy link
Author

You're right, it wasn't thought as running code. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment