Edward Z. Yang wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Tim Starling wrote:
I wouldn't recommend leaving the var out when there is a need to initialise it to something simple, and you would need to add an isset(): [snip] The second one is slower.
Right. A little murkier would be something like
var $foo;
Which declares the variable and is a convenient point for documentation. I've always thought that adding this little marker allowed the Zend Engine to optimize access to the variable, much like a C struct. If I'm reading you correctly, apparently not! (It's really hard to test for micro-optimizations like these, and I can't read C well enough to make determinations on my own).
And, of course, conditional includes, although annoying to bytecode caches, let you bypass the overhead of loading all the opcodes altogether. There's a balance to be had there, and I'm curious to know what works and what doesn't.
But please don't forget my main point: an object is a hashtable, you can add and remove variables. Don't be such a stickler for self-documentation and the way things are "meant" to be done that you tie yourself in knots trying to avoid dynamic variable creation. You can always document with a comment instead.
There's an interesting question: why objects over arrays? (There's a simple answer to that, and it is that most of the time, you're dealing with an object, not an array, and shouldn't have to allocate another hash table for some custom properties.)
^_^ For me... I just like accessing data with a $foo->bar rather than $foo['bar'], former one looks a bit nicer to me.
Also, you might be interested in the "Class Properties in Interfaces?" discussion that was recently floating around on php.internals, that proposed that unsetting a variable from an interface should cause a fatal error. :-P (You're probably not; it's a really long discussion). -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFINjY6qTO+fYacSNoRAntiAJ9NczepsswzI8h3Tg0u5WfzmXaq6QCeO2Ww +peoZNen2GlPtwj0hCx+tFI= =nVh4 -----END PGP SIGNATURE-----
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
~Daniel Friesen(Dantman) of: -The Gaiapedia (http://gaia.wikia.com) -Wikia ACG on Wikia.com (http://wikia.com/wiki/Wikia_ACG) -and Wiki-Tools.com (http://wiki-tools.com)