2021/07/31/a code mystery: Difference between revisions
Jump to navigation
Jump to search
m (→Conundrum) |
|||
Line 30: | Line 30: | ||
It doesn't make sense, because the default IOUnit class retrieved (into $sClass, in part 2), <code>ferret\data\bank\cIOUnitSimple</code>, is in fact directly descended from <code>ferret\data\bank\cIOUnit</code> (in part 1). I can only think I'm reading the definition of <code>is_a()</code> wrong somehow. | It doesn't make sense, because the default IOUnit class retrieved (into $sClass, in part 2), <code>ferret\data\bank\cIOUnitSimple</code>, is in fact directly descended from <code>ferret\data\bank\cIOUnit</code> (in part 1). I can only think I'm reading the definition of <code>is_a()</code> wrong somehow. | ||
Tenatatively: [https://www.php.net/manual/en/function.is-a <code>is_a()</code>] is messed up; [https://www.php.net/manual/en/function.is-subclass-of.php <code> | Tenatatively: [https://www.php.net/manual/en/function.is-a <code>is_a()</code>] is messed up; use [https://www.php.net/manual/en/function.is-subclass-of.php <code>is_subclass_of()</code>] instead. |
Revision as of 21:04, 1 August 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.