Posted by Edward Z. Yang on 06/07/07 02:04
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jon Slaughter wrote:
> is there any way to simply add an attribute like feature to a
> function/method definition? [snip]
You want the "Strategy" pattern, making the function into an object:
class TestFunction
{
var $probability = 0.234321;
function call() { /* ... */ }
}
$func = new TestFunction();
$func->call();
PHP does not treat anonymous functions as first-class objects, unlike
JavaScript, so some acrobatics are necessary to get this working.
- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org> Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGZ2e0qTO+fYacSNoRAtagAJ9IV0oTUmLhpSlWSA1LBsBY7TYjCwCfft6H
noiOwWISbfNGx8RGy/+EfBM=
=er7e
-----END PGP SIGNATURE-----
Navigation:
[Reply to this message]
|