On 09/09/10 22:49, Chad wrote:
Is there a reason __clone() couldn't (shouldn't?) call clearState()?
I think that would count as "surprising" (as in the principle of least surprise). Coders would not expect "clone $parser" to clear the state in the new clone. It's conceivable that it could introduce bugs. Also clearState() is fairly slow, so you wouldn't want to call it more times than necessary.
Something like Parser::cloneAndClear() could be documented to return a clone of $this and simultaneously clear the state, that would be somewhat less likely to surprise.
-- Tim Starling