mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
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.
This commit is contained in:
parent
45ab2d9ab6
commit
61c3b60c03
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user