Parsoid
A bidirectional parser between wikitext and HTML5
|
This class contains sundry helpers unrelated to core Parsoid. More...
Static Public Member Functions | |
static | arrayToObject ( $array) |
Convert an array to an object. | |
static | iterable_to_array (iterable $iterable) |
Convert an iterable to an array. | |
static | jsonEncode ( $o) |
json_encode wrapper function | |
This class contains sundry helpers unrelated to core Parsoid.
|
static |
Convert an array to an object.
Workaround for https://bugs.php.net/bug.php?id=78379
PHP 7 introduced "efficient" casting of arrays to objects by taking a reference instead of duplicating the array. However, this was not properly accounted for in the garbage collector. The garbage collector would free the array while it was still referred to by live objects.
The workaround here is to manually duplicate the array. It's not necessary to do a deep copy since only the top-level array is referenced by the new object.
It's only necessary to call this for potentially shared arrays, such as compile-time constants. Arrays that have a reference count of 1 can be cast to objects in the usual way. For example, array literals containing variables are typically unshared.
array | $array |
|
static |
Convert an iterable to an array.
This function is similar to but not the same as the built-in iterator_to_array, because arrays are iterable but not Traversable!
This function is also present in the wmde/iterable-functions library, but it's short enough that we don't need to pull in an entire new dependency here.
@phan-template T
iterable<T> | $iterable |
|
static |
json_encode wrapper function
mixed | $o |