Skip to content

Instantly share code, notes, and snippets.

@jesseschalken
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseschalken/78c9e0818cadf4a4ec58 to your computer and use it in GitHub Desktop.
Save jesseschalken/78c9e0818cadf4a4ec58 to your computer and use it in GitHub Desktop.
Handy functions for working with references in PHP
<?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