|
Posted 2003 or so I needed some valid SWF files with constrained character sets for an injection PoC. Putting them here in case someone else needs some. PHP has finally taken the plunge into the 1960s by implementing GOTO. Here's an implementation for Java. A patch for a serious Java bug. No longer needed as of June 16. Max & Michael have written a Max/MSP driver based on the multitouch code.
My CSS-fu is weak; please use a recent browser. Random, semi-related image by Andrew*. |
PHP ClosuresA hacky implementation of closures for PHP. This article is from 2004 and is kept here for historical reasons. Apparently (as of 2008) PHP will get native support for closures soon, making this ugly hack even less useful. Why?!A closure is a standard feature found of most modern languages. Here's one explanation, and here's another... there's a nice Wikipedia article as well. What we would like to haveIdeally, we could say something like this: function rot13widget() {
$a = new TextField();
$b = new Button('Rotate!');
$b->setClickHandler(function() { // NOT VALID CODE!
$a->setText(str_rot13($a->getText()));
});
return Layout::horizontal($a, $b);
}
$panel->add(rot13widget());
... the point being that the function object passed to onClick contains the necessary pointers to $a.
What we can getWe don't really want to add more stuff to the PHP parser. We can settle for this: function rot13widget() {
$a = new TextField();
$b = new Button('Rotate!');
$b->setClickHandler(eval(closure('
$a->setText(str_rot13($a->getText()));
')));
return Layout::horizontal($a, $b);
}
The button class would just store the function object, and call it like this: class Button {
function setClickHandler($o) {
$this->clickHandler = $o;
}
function handleClick() {
if($this->clickHandler)
$this->clickHandler->call();
}
}
The hassle of maintaining the necessary pointers to the various widgets would be handled invisibly by the closure "library". ImplementationWhat we do (internally) is this: the closure() function takes the snippet of code, does a very cheesy parse of it, and returns a magic string which is then evaluated by passing it to eval(). That code grabs the necessary variables from the outer scope, and wraps them in a Closure object. That object is then returned to the function that needs it. The call above would result in this string: new Closure(
'$a->setText(str_rot13($a->getText()));',
array('a' => &$a));
Here's the actual code:
Comments |