This is made possible by the introduction of closures in PHP 5.3 which I think was long overdue. However, in this specific case it's worth noting that many times in JavaScript objects declared like this<p><pre><code> var fido = {name: "Fido", barks: true};
</code></pre>
are not actually used as objects but instead emulate a name-value container - and this is a piece of functionality that PHP already supports natively due to its array type. Of course it's nice that you can now assemble objects on the fly, but people coming from JavaScript should be reminded that it's not necessary to use PHP objects in this fashion most of the time.<p><i>Edit: it was PHP 5.3, not 5.2</i>