Skip to content

Instantly share code, notes, and snippets.

@bitops
Created October 24, 2011 18:21
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 bitops/1309707 to your computer and use it in GitHub Desktop.
Save bitops/1309707 to your computer and use it in GitHub Desktop.
Not doing PHP correctly?
<?php
class Dummy {
public $foos = array();
public function & getFoos() {
return $this->foos;
}
public function addFoo($foo) {
array_push($this->foos, $foo);
}
}
$d = new Dummy();
var_dump($d);
$d->addFoo("a");
$d->addFoo("b");
$d->addFoo("c");
var_dump($d); //has 3
$foos = &$d->getFoos(); //mystery solved
unset($foos[1]);
var_dump($d);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment