Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Ext\PHPUtils Class Reference

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
 

Detailed Description

This class contains sundry helpers unrelated to core Parsoid.

Member Function Documentation

◆ arrayToObject()

static Wikimedia\Parsoid\Ext\PHPUtils::arrayToObject ( $array)
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.

Parameters
array$array
Returns
\stdClass

◆ iterable_to_array()

static Wikimedia\Parsoid\Ext\PHPUtils::iterable_to_array ( iterable $iterable)
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.

See also
https://stackoverflow.com/questions/44587973/php-iterable-to-array-or-traversable
https://github.com/wmde/iterable-functions/blob/master/src/functions.php

@phan-template T

Parameters
iterable<T>$iterable
Returns
array<T>

◆ jsonEncode()

static Wikimedia\Parsoid\Ext\PHPUtils::jsonEncode ( $o)
static

json_encode wrapper function

  • unscapes slashes and unicode
Parameters
mixed$o
Returns
string

The documentation for this class was generated from the following file: