Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108884 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65467 invoked from network); 6 Mar 2020 11:10:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Mar 2020 11:10:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6C361804D9 for ; Fri, 6 Mar 2020 01:30:02 -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,RCVD_IN_MSPIKE_H2,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-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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, 6 Mar 2020 01:30:02 -0800 (PST) Received: by mail-lj1-f171.google.com with SMTP id a10so1444875ljp.11 for ; Fri, 06 Mar 2020 01:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=cyGrf73dZe+/h/96LFWhwpdcyEWRBZjNlxCC6olCyqc=; b=iQNy/t7aoQgEc3DTmY2o5UmqHxOyFGQuKTTfYKDSC3thsePNIiW5ZqlyXvYgrMAe2n e+CS3ihcn3qcY0mrCmHArrxTVLTxbadN/UwxXYxriUnNMLi/5djTyls13c2sGwSqzZCi Oi+Ys+F3IbucvuP2z9dyGbg3W9bPCrHk0vbP6wF+2h8pYaAvJrbY287csSSzPXwLGx1N bi5eI6RWQ0AJs70Nc3hWnwbAHpySJWnLK/iCmxq0PA3yKhoMDbhsEtRVyE8w+xJeIm5B BYjTFT61ZYQ+JhIo+EFQIcnE+XLjQDxuvxqO3Gb2jqpL1v12ykayOcflWAM3JjPr5iBh 9KDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=cyGrf73dZe+/h/96LFWhwpdcyEWRBZjNlxCC6olCyqc=; b=IhF237XgrA9HyzMXrF80xAFRHD8FdTYa0Fp2SveqRl1n5ZA5ZFdeTMSQqqs7oncrDM AxomJBuOl7a9laqMvdCutIxKeDbpeQMt+bBRXs/wDQyGeGA9dtSsn04triNHC4cG6e4p eGIYXt7jVgwlNzvYu1fGCkfv89QVWXbv75ZcYE+PgadYUj3vjeOd53VDDCxHGOoxZ8ZT f0EVWNscOg4Pj99EyMzDGs/cRptSkkuNqn/2kXaMCcL2YOsb487b9HQO1Zm8wd5ndT1z wZooy5jziNcrHOABHr+2d6+hQhw6HosHBXWKQdL2JHoiItmZ+/DlRfJE4Q2NNuKzD8Vy EDVQ== X-Gm-Message-State: ANhLgQ2bKalbjvr6LEHDEI3MR/2vJxjAwhZTjMArqzAPlxEhW8spfLgl 1StOkl0kcppaRz79VcKfbKIw5Xoc2YlYRKBh1nPp9tuRyMtkRQ== X-Google-Smtp-Source: ADFU+vsx8UDEYs2OM4nozxVANfXJa6L8ehy3v2apCSF4pIp7e0lyk1S9Fcs3NfKCoyQ1pL1HVtjvxiEQIMenzBBrN44= X-Received: by 2002:a2e:7806:: with SMTP id t6mr1545156ljc.145.1583486999019; Fri, 06 Mar 2020 01:29:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 6 Mar 2020 10:29:42 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000015490c05a02c4c8c" Subject: Re: SimpleXMLIterator From: nikita.ppv@gmail.com (Nikita Popov) --00000000000015490c05a02c4c8c Content-Type: text/plain; charset="UTF-8" On Fri, Feb 28, 2020 at 11:59 AM Nikita Popov wrote: > 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? > I've put up https://github.com/php/php-src/pull/5234 to implement this... Nikita --00000000000015490c05a02c4c8c--