Skip to content

Instantly share code, notes, and snippets.

@axgle
Last active August 29, 2015 14:01
Show Gist options
  • Save axgle/057ed695199fca4d1d8e to your computer and use it in GitHub Desktop.
Save axgle/057ed695199fca4d1d8e to your computer and use it in GitHub Desktop.
<?php
class db{
static $count=0;//current data
static $undos=array();//stack
}
function add($n){
db::$count+=$n;
db::$undos[]=function() use($n){
db::$count-=$n;
echo "undo:$n\n";
};
echo db::$count." current\n";
}
function undo(){
if(db::$undos){
$func=array_pop(db::$undos);
$func();
echo " ".db::$count."\n";
};
}
add(1);add(2);add(3);/*undo();*/add(4);
undo();undo();undo();
/**
simple Command Pattern example which performs Undo operation on a calculator:
http://www.php.net/manual/pt_BR/language.oop5.patterns.php#106747
JavaScript Undo Manager:
https://github.com/ArthurClemens/Javascript-Undo-Manager
How to write a simple undo system for your app :
http://www.javascriptkata.com/2010/03/29/how-to-write-an-simple-undo-system-for-your-app/
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment