Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>This also arises if you compare recursive objects using <code>==</code> instead of <code>===</code></h2> <p><strong>If you need to compare actual object instances</strong> always use the strict comparison operator <code>===</code> as it only compares if the objects refer to the same instance of the same class.</p> <p>Short explanation:</p> <p>If you compare objects using <code>$object == $objectToCompareWith</code>, PHP is comparing every attribute and value of the first object with the second. This comparison is recursive over objects which are properties of the objects being compared.</p> <p>That means that if both objects share an attribute with an object as its value, PHP does the same <code>==</code> comparison between those attribute objects. Now as soon as on of those attribute objects is recursive (e.g. a self referencing object) the comparison recurses down too until the maximum nesting level is reached.</p> <p>As stated in the comments by Josh Stuart and mazatwork, strict comparison can be forced when using array functions like <code>in_array()</code> and <code>array_search()</code> by setting their respective <code>$strict</code> parameter to <code>true</code>.</p> <p><a href="http://www.richardlord.net/blog/php-nesting-level-too-deep-recursive-dependency" rel="noreferrer">Richard Lord: "Nesting level too deep – recursive dependency?"</a></p> <p><a href="http://www.php.net/manual/en/language.oop5.object-comparison.php" rel="noreferrer">PHP Manual: "Comparing Objects"</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload