mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 07:39:54 +02:00
MDL-66968 php74: array_key_exists() for objects is deprecated
Replace it for correct property_exists() when the element being inspected is a property of object/class. Amended and squased changes: - keep mongo unmodified. The information is array, hence correct. - fix a couple of messaging phpdocs that were incorrect. Amended take#2: - As far as mongo resturns BSONDocument that is ArrayObject, aka implements ArrayAccess, we have decided to explicitly cast results to array so existing array_key_exists() and other accesses will continue working the same.
This commit is contained in:
parent
aaff6692a1
commit
f4feabb83f
21 changed files with 36 additions and 30 deletions
8
cache/stores/mongodb/lib.php
vendored
8
cache/stores/mongodb/lib.php
vendored
|
@ -254,7 +254,13 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
|||
}
|
||||
|
||||
$result = $this->collection->findOne($key);
|
||||
if ($result === null || !array_key_exists('data', $result)) {
|
||||
// Note $result is really an object, BSONDocument extending ArrayObject,
|
||||
// which implements ArrayAccess. That enables access to its information
|
||||
// using square brackets and some array operations. But, it seems that
|
||||
// it's not enough for array_key_exists() to operate on it. Hence, we
|
||||
// are explicitly casting to array, after having checked that the operation
|
||||
// doesn't incur into any performance penalty.
|
||||
if ($result === null || !array_key_exists('data', (array)$result)) {
|
||||
return false;
|
||||
}
|
||||
$data = @unserialize($result['data']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue