Created
May 8, 2017 13:58
-
-
Save panvid/5c9ab1182a7265166edd9bcdef404487 to your computer and use it in GitHub Desktop.
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 | |
class A { | |
public $var = "blub"; | |
function __toString() { | |
return $var; | |
} | |
} | |
function makeBlab($object) { | |
$object->var = "overridden"; | |
} | |
function makeAClass($object) { | |
$object = new A(); | |
} | |
function makeArray($object) { | |
$object = []; | |
} | |
function makeArrayWithReference(&$object) { | |
$object = []; | |
} | |
$a = new A(); | |
echo print_r($a, true) . '<br/>'; | |
// objects will be hand over as reference, so will be manipulated in function | |
makeBlab($a); | |
echo print_r($a, true) . '<br/>'; | |
// try to override this object with a new initialized one | |
makeAClass($a); | |
echo print_r($a, true) . '<br/>'; | |
// try to override this object with an array | |
makeArray($a); | |
echo print_r($a, true) . '<br/>'; | |
// try to override this object with an array. Use the values a reference | |
makeArrayWithReference($a); | |
echo print_r($a, true) . '<br/>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment