Yay! I use PHP SPL today. It turns me on. OMFG!! It feels so damn good. basically it was a copy paste action, and then adjusting how the method should work for each interface ArrayAccess Iterator and Countable). Countable implemented with a bit of twist since the class is not available in my version of PHP. The method ‘countable’ is still a part of ArrayAccess but the doc says it’s separated already. Thus I came up with this simple solution:
if (class_exists('Countable', false)) :
SysLog::Log('Countable class found: using implements Countable', 'sanitizer');
abstract class VarBase extends XVarBase implements Countable {
//Region Countable
function count()
{
return count(array_keys($this->mCompound));
}
//EndRegion
}
else:
SysLog::Log('Countable class not found: using regular extends (without implements)', 'sanitizer');
abstract class VarBase extends XVarBase {
//Region Countable
function count()
{
return count(array_keys($this->mCompound));
}
//EndRegion
}
endif;
Where XVarBase already implements ArrayAccess and Iterator. “OMG, where have you been” you may say. We’ve got something like that in C++ for ages! Well, pardon my lack of nerdiness here
.
Yay, SPL is so fun!!!