function ExportUtil::toArray
Converts an object to an array containing all of its private, protected and public properties.
Parameters
mixed $value:
Return value
array<mixed>
1 call to ExportUtil::toArray()
- ExportUtil::recursiveExport in vendor/
phpspec/ prophecy/ src/ Prophecy/ Util/ ExportUtil.php - Recursive implementation of export
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Util/ ExportUtil.php, line 52
Class
- ExportUtil
- This class is a modification from sebastianbergmann/exporter
Namespace
Prophecy\UtilCode
public static function toArray($value) {
if (!is_object($value)) {
return (array) $value;
}
$array = array();
foreach ((array) $value as $key => $val) {
// properties are transformed to keys in the following way:
// private $property => "\0Classname\0property"
// protected $property => "\0*\0property"
// public $property => "property"
if (preg_match('/^\\0.+\\0(.+)$/', $key, $matches)) {
$key = $matches[1];
}
// See https://github.com/php/php-src/commit/5721132
if ($key === "\x00gcdata") {
continue;
}
$array[$key] = $val;
}
// Some internal classes like SplObjectStorage don't work with the
// above (fast) mechanism nor with reflection in Zend.
// Format the output similarly to print_r() in this case
if ($value instanceof \SplObjectStorage) {
foreach ($value as $key => $val) {
// Use the same identifier that would be printed alongside the object's representation elsewhere.
$array[spl_object_id($val)] = array(
'obj' => $val,
'inf' => $value->getInfo(),
);
}
}
return $array;
}