2021/07/31/a code mystery: Difference between revisions
Jump to navigation
Jump to search
m (→Conundrum) |
No edit summary |
||
Line 1: | Line 1: | ||
{{nav/codeblog}} | |||
==Part 1== | ==Part 1== | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> |
Latest revision as of 01:59, 23 November 2021
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.