From 1daec62c0ab6590d3a30464b2f679baea3ca3936 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 20 Sep 2018 00:09:08 -0400 Subject: table: Fix bug in constructor This particular flaw was dampening (and could popentially be hiding) the effects of other bugs. For instance, in this case, a GUID of "" was invalidly being used to construct an object. This should obviously be considered an error, but since "" evaluates to false, the construction was treated as default (no GUID) construction and succedded. It wasn't until later when missing properties were accessed that random PHP error messages clued me into what was happening. Now, when any sort of explicit value is used to construct an object (not NULL), an object load will be attempted, giving bad input more chances to fail outright and trigger an exception. In addition, the 'no such guid' exception message is updated to place quotes ('') around the GUID string to make it more obvious when "" is used in the future. --- app/class/table.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/class/table.class.php b/app/class/table.class.php index 5e4c823..618d938 100644 --- a/app/class/table.class.php +++ b/app/class/table.class.php @@ -37,7 +37,7 @@ abstract class table */ public function __construct(?string $guid = NULL) { - if ($guid) + if ($guid !== NULL) $this->loadObj($guid); } @@ -51,7 +51,7 @@ abstract class table $guid = database::esc($guid); if (!self::isGUID($guid)) - throw new Exception("GUID " . $guid . " does not exist"); + throw new Exception("GUID '" . $guid . "' does not exist"); foreach ($this->fields as $tbl => $flds) { -- cgit v1.2.3