Created
February 23, 2012 19:43
-
-
Save timplunkett/1894660 to your computer and use it in GitHub Desktop.
PHP 5.3 object passing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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