2

I'm trying to "diff" two arrays and PHP is returning the following error:

Catchable fatal error: Object of class Node could not be converted to string in D:\projetos\labs\dok\dev\application\models\dok.php on line 410

my arrays are, respectively:

array(2)
    object(Node)#5 ...[7 attributes]
    object(Node)#6 ...[7 attributes]

array(1)
    object(Node)#5 ....[7 attributes]

I would really appreciate some help here as I have no clue of what's going on.


as requested, the code around the diff:

// is it a distant child?
$all_childs = $node->get_childs(true);
$distant_childs = array_diff($all_childs, $childs);
if(in_array($this, $distant_childs))
    return 'distant-child';
2

1 Answer 1

2

Note:

Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

If the element is object, you need to provide __toString() method for the object, or you did it by yourself.

Sign up to request clarification or add additional context in comments.

1 Comment

wow! it worked just with a simple serialize()! I have to confess that i'm seeing this as a php "bug" :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.