Attributes By Reference
PHP Fusebox uses the $attributes "scope" (in PHP it's really just an array, not a "scope") for all almost all input. This was grandfathered in from the ColdFusion port, where #attributes# was used. This was useful back when you could CFMODULE into the fusebox app and pass attributes back in. I'm not sure if it's still useful anymore. I'm sure CF Fuseboxers have differing opinions on this matter.
Anyway, I'm concerned about losing my wrists to CT later in life, I'm tied of typing "attributes", and I'm just plain lazy. The good news is in PHP a reference to a variable will be updated with changes to the referenced variable. Por ejemplo:
// make the original array $attributes = array(); $attributes['test'] = 'hello world'; // create a reference $a = &$attributes; $attributes['test'] = 'Hello, World!'; $attributes['test2'] = 'Goodbye, Cruel World!'; // the reference will show // the changes to the original (hooray!) print_r($a);
The result:
Array
(
[test] => Hello, World!
[test2] => Goodbye, Cruel World!
)
In other words, $a will always keep up-to-date with $attributes. OK, this is not a shocking PHP revelation, but it was news to me. Henceforth, I'm putting this in my fusebox.init.php file on new projects, and I will code my fuse files accordingly. (On all projects I can get away with it on, that is... like my personal stuff)
$a = &$attributes;
Trackback: http://philsown.org/2006/07/attributes-by-reference/trackback
How to Put Your Face Next to Your Comment