Skip to content

Commit

Permalink
Do not call "toArray" if private or not an object
Browse files Browse the repository at this point in the history
  • Loading branch information
Elektordi committed Nov 15, 2016
1 parent b5cc45c commit 71878d2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Utility/Xml.php
Expand Up @@ -203,8 +203,8 @@ protected static function _loadXml($input, $options)
*/
public static function fromArray($input, $options = [])
{
if (is_object($input) && method_exists($input, 'toArray')) {
$input = $input->toArray();
if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
$input = call_user_func([$input, 'toArray']);
}
if (!is_array($input) || count($input) !== 1) {
throw new XmlException('Invalid input.');
Expand Down Expand Up @@ -257,8 +257,8 @@ protected static function _fromArray($dom, $node, &$data, $format)
}
foreach ($data as $key => $value) {
if (is_string($key)) {
if (is_object($value) && method_exists($value, 'toArray')) {
$value = $value->toArray();
if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
$value = call_user_func([$value, 'toArray']);
}

if (!is_array($value)) {
Expand Down Expand Up @@ -323,8 +323,8 @@ protected static function _createChild($data)
{
extract($data);
$childNS = $childValue = null;
if (is_object($value) && method_exists($value, 'toArray')) {
$value = $value->toArray();
if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
$value = call_user_func([$value, 'toArray']);
}
if (is_array($value)) {
if (isset($value['@'])) {
Expand Down

0 comments on commit 71878d2

Please sign in to comment.