From 61c3b60c03c053c809182e49b96aa5ecd8ebf3b1 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 1 Sep 2014 11:18:16 +0100 Subject: [PATCH] MDL-44725 Update cm_info::create to allow 'false' param (13) Currently cm_info::create allows the 'null' parameter, and returns null (as a null $cm should still be null when treated as a cm_info object). Some unit tests relied on the value 'false' being treated the same as null in this regard. This seems like a generally safe assumption (given this is a function about changing weakly typed data into a stronger type) so I modified the function to accept anything PHP false, returning null. --- lib/modinfolib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 9b6e9c3f5b4..13380a5ce5e 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -1739,13 +1739,13 @@ class cm_info implements IteratorAggregate { * Creates a cm_info object from a database record (also accepts cm_info * in which case it is just returned unchanged). * - * @param stdClass|cm_info|null $cm Stdclass or cm_info (or null) + * @param stdClass|cm_info|null|bool $cm Stdclass or cm_info (or null or false) * @param int $userid Optional userid (default to current) - * @return cm_info|null Object as cm_info, or null if input was null + * @return cm_info|null Object as cm_info, or null if input was null/false */ public static function create($cm, $userid = 0) { - // Nulls get passed through. - if (is_null($cm)) { + // Null, false, etc. gets passed through as null. + if (!$cm) { return null; } // If it is already a cm_info object, just return it.