Last active
August 29, 2015 14:27
-
-
Save jesseschalken/78c9e0818cadf4a4ec58 to your computer and use it in GitHub Desktop.
Handy functions for working with references in PHP
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 | |
final class ref { | |
static function &mk($x) { return $x; } | |
static function get(&$x) { return $x; } | |
static function set(&$x, $y) { $x = $y; } | |
static function inc(&$x) { $x++; } | |
static function dec(&$x) { $x--; } | |
static function swap(&$x, &$y) { | |
$_ = $x; | |
$x = $y; | |
$y = $_; | |
} | |
static function eq(&$x, &$y) { | |
$_ = $x; | |
$x = new \stdClass; | |
$r = $x === $y; | |
$x = $_; | |
return $r; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment