i have written file-handler-class, works this:
__constructopens , ex-locks file, reads json-content , parses php-array, keeping property of class.- the file still locked, in order avoid race-conditions.
- other 'worker-classes' make changes in array, in/from other scopes.
__destructencodes finished array, writes file, , unlocks file.
everything works fine ...
question:
is sensible keep array property of original class, or better pass array worker-classes, , let them return @ end?
perhaps there way keep array locally, , pass worker-classes reference, instead of raw data?
i mean ... question of not having duplicates, waisting memory. question of speed, not passing things unnecessarily. , question of best practices, keeping things easy understand.
actually, passing array function, having function modify array, , return other caller may or may not conduct modifications on it, in fact copying array multiple times (since invokes copy-on-write semantics in php) , definition wasting memory.
whereas keeping property of object instance, not invoking copy-on-write semantics, if caller not same instance. since passing object instance won't copy array, nor modification said instance.
not mention make easier retain state within object (assuming care validation).
Comments
Post a Comment