2021/07/31/a code mystery

From Woozle Writes Code
Jump to navigation Jump to search

Part 1

namespace ferret\data\bank;

[...]

class cIOUnitSimple extends cIOUnit {

Part 2

namespace ferret\data;
use ferret\data\bank\cIOUnit;
use ferret\data\bank\cIOUnitSimple;

[...]

$sClass = $this->DefaultIOUnitClass();
if (is_a($sClass,cIOUnit::class)) {
    // create new I/O Unit object
    $oIOUnit = new $sClass($this,$ouNative);
} else {
    $s = "Default IOUnit class is [$sClass], which is not a cIOUnit.";
    $e = new \ferret\except\cInternal($s);
    throw $e;
}

Part 3 - output

Internal ferret panic: Default IOUnit class is [ferret\data\bank\cIOUnitSimple], which is not a cIOUnit.

Conundrum

It doesn't make sense, because the default IOUnit class retrieved (into $sClass, in part 2), ferret\data\bank\cIOUnitSimple, is in fact directly descended from ferret\data\bank\cIOUnit (in part 1). I can only think I'm reading the definition of is_a() wrong somehow.

Tenatatively: is_a() is messed up; use is_subclass_of() instead.