2021/07/31/a code mystery: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==Part 1== <syntaxhighlight lang=php> namespace ferret\data\bank; [...] class cIOUnitSimple extends cIOUnit { </syntaxhighlight> ==Part 2== <syntaxhighlight lang=php> namesp...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{nav/codeblog}} | |||
==Part 1== | ==Part 1== | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> | ||
Line 29: | Line 30: | ||
==Conundrum== | ==Conundrum== | ||
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; use [https://www.php.net/manual/en/function.is-subclass-of.php <code>is_subclass_of()</code>] instead. |
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.