php / php/php-src

SimpleXML element comparison is broken

Open
#12,171 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: simplexml Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

$xml = "<root><first/><second/><third/></root>";
$xml = simplexml_load_string($xml);
var_dump($xml->first == $xml->second);

Resulted in this output:

bool(true)

But I expected this output instead:

bool(false)

It's because the wrong node is fetched, i.e. it doesn't take into account the iterating nature of the simple xml objects. PoC fix patch (needs more testing and thinking): https://gist.github.com/nielsdos/f8e232836d72e68c5d3418116ddad877

PHP Version

PHP 5.0.0-master

Operating System

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the SimpleXML reproducer from the issue and trace how comparison of $xml->first and $xml->second selects nodes. Use the linked PoC patch as context, then verify that the same example reports bool(false) and check related SimpleXML comparison behavior for regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.