Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108789 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4626 invoked from network); 28 Feb 2020 12:42:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Feb 2020 12:42:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2945F1804F4 for ; Fri, 28 Feb 2020 03:00:17 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 28 Feb 2020 03:00:16 -0800 (PST) Received: by mail-lf1-f42.google.com with SMTP id n25so1806095lfl.0 for ; Fri, 28 Feb 2020 03:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=p15QIbdSL1CIa0UXxNefw/ouwjDLSg5Q/aoc3Mafc+I=; b=rbTUKQsE3TenlzUT6xvOTU3Lu5xAkQEe1MTB+KDMJ73/bJmeL+kAO3H/Ivnl9L0QfM oOqKnWvzFYaZE0rywGzICRFVsogkw1Cnkk/TH6ZGM26t4nuLUt7jdW2V7NuFi/JHL5lM 3wXZ/19GSf0Pnt02sEMYFt/ZsOyS2nZWfc1TB1fuDBd9Sq0kBzW1WAL/Vl15V8+ttKN7 BYF2OarJlVt3vGynVmk97FXMc1WBm18tTqrslsFoJ4r1E8KAgPTaRdTBcORs9QUHzgs7 owqwHN5droPgDZVwLM83DxHelHIHM2WqKwCujPhv04ZocVHa1a0Z1WRbE6W16+9QQizD JVIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=p15QIbdSL1CIa0UXxNefw/ouwjDLSg5Q/aoc3Mafc+I=; b=NDhSNk8c71SUTjtr1KoWd4xfmTkd1kxbUYbEgP60trYCd/qGPiYz+mK0moY1hS378L 2gPwLQolD7G2Hc2TZAPYW9LSf0ra2FmHXVVvYq9jcc/N0xafwgbsZqlfccv7Rote0gBU sqZ+QObAMwQD23jWZ+/rD8aFJ62VcVv9VnAVEPiYYmdoahFev9RHYWCbUbEJeMAb3KjQ NEn01ofmKDI6lKHwHQ6eRPtIgh33ExPiEXKommzynp0WWdxGfKJr6er1KL5m9z9YXm9b cjKYrqz6hdgK1m3Qp9mbsafoCPyBRcAm6MydPi+Ou9oRVhy4moOtxUSYXEFmmId3vb42 trTg== X-Gm-Message-State: ANhLgQ206uW3dMwjL87iiraa26WIgltgi3HfvwzVCfiHSjGT+zJ7th+H XNWug/ET0VmDjTvEDNApI/b/hKAl4+hnN6QuEffuftqiN/e6Fw== X-Google-Smtp-Source: ADFU+vvxa93ICyvNMCy+50lQXYV3XDoVhWakxLLmwvhjXvrATvvgAPPTfiLcNiLml3e05XXdKj9NhZfKt+vqVXD9otQ= X-Received: by 2002:ac2:596d:: with SMTP id h13mr2347870lfp.190.1582887612417; Fri, 28 Feb 2020 03:00:12 -0800 (PST) MIME-Version: 1.0 Date: Fri, 28 Feb 2020 11:59:56 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000db8a98059fa0bdfc" Subject: SimpleXMLIterator From: nikita.ppv@gmail.com (Nikita Popov) --000000000000db8a98059fa0bdfc Content-Type: text/plain; charset="UTF-8" Hi internals, I'm currently trying to make sure that all internal Traversable classes implement either Iterator or IteratorAggregate. This is a hard requirement for userland classes, but internal classes can get away with implementing only the internal get_iterator() mechanism. ( https://github.com/php/php-src/pull/5216) One problem I ran into along the way is the SimpleXMLIterator class. A naive person might think that there is some sanity left in this world, and the hierarchy for SXE/SXI looks like this: SimpleXMLElement implements IteratorAggregate // where SimpleXMLElement::getIterator() returns: SimpleXMLIterator implements Iterator Of course, they would be wrong. The actual hierarchy is this: SimpleXMLElement implements Traversable SimpleXMLIterator extends SimpleXMLElement implements Iterator The fact that SimpleXMLIterator extends SimpleXMLElement leaves me in a tough spot, because it means SimpleXMLElement cannot be an IteratorAggregate -- that would mean that SimpleXMLIterator implements both IteratorAggregate and Iterator, which is not permissible. It seems that it's also not possible to remove the "extends" without a non-trivial backwards-compatibility break, because apparently writing simplexml_load_string($str, 'SimpleXMLIterator') is a thing, which requires SimpleXMLIterator to extend SimpleXMLElement (and possibly is the reason why this was done in the first place.) The only way out I see here is to lift the methods from SimpleXMLIterator into SimpleXMLElement, make SimpleXMLElement implement Iterator itself, and basically leave SimpleXMLIterator as a dummy extension of SimpleXMLElement. Does that sound "reasonable"? Or rather, is there something more reasonable that can be done? Regards, Nikita --000000000000db8a98059fa0bdfc--