Last active
July 6, 2022 03:37
-
-
Save newhope/a04cfa1b9b0674cfbdabfaba7166081c to your computer and use it in GitHub Desktop.
PHP Pointer Class
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 Pointer { | |
private $obj; | |
public function __construct( & $anything) { | |
$this->obj = & $anything; | |
} | |
public function & get() { | |
return $this->obj; | |
} | |
} | |
// Sample usage | |
$v1 = 'a'; | |
$p1 = new Pointer($v1); | |
echo $p1->get(); // Output: 'a' | |
$v1 = 'b'; | |
echo $p1->get(); // Output: 'b' | |
$same_val = & $p1->get(); | |
$v1 = 'c'; | |
echo $same_val; // Output: 'c' | |
$same_val = 'd'; | |
echo $v1; // Output: 'd' | |
$p2 = new Pointer($same_val); | |
$v1 = 'e'; | |
echo $p1->get(); // Output: 'e' | |
echo $p2->get(); // Output: 'e' | |
$same_val = 'f'; | |
echo $p1->get(); // Output: 'f' | |
echo $p2->get(); // Output: 'f' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment