Skip to content

Instantly share code, notes, and snippets.

@timplunkett
Created February 23, 2012 19:43
Show Gist options
  • Save timplunkett/1894660 to your computer and use it in GitHub Desktop.
Save timplunkett/1894660 to your computer and use it in GitHub Desktop.
PHP 5.3 object passing
<?php
function pass_by_pointer($obj = NULL) {
$obj->value = 5;
}
function pass_by_reference(&$obj = NULL) {
$obj->value = 4;
}
$obj = NULL;
pass_by_pointer($obj);
print_r('pass_by_pointer(NULL):' . "\n");
var_dump($obj);
$obj = NULL;
pass_by_reference($obj);
print_r('pass_by_reference(NULL):' . "\n");
var_dump($obj);
$obj = new stdClass();
pass_by_pointer($obj);
print_r('pass_by_pointer($obj):' . "\n");
var_dump($obj);
$obj = new stdClass();
pass_by_reference($obj);
print_r('pass_by_reference($obj):' . "\n");
var_dump($obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment