Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108792 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74493 invoked from network); 28 Feb 2020 21:41:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Feb 2020 21:41:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE0AD1804F4 for ; Fri, 28 Feb 2020 11:59:25 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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-yw1-f52.google.com (mail-yw1-f52.google.com [209.85.161.52]) (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 11:59:25 -0800 (PST) Received: by mail-yw1-f52.google.com with SMTP id n1so3963775ywe.13 for ; Fri, 28 Feb 2020 11:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=a9NRGiq5nhs+B8ZtijmMWEf8pObEs71q+nkeZNuFE/Q=; b=TniWtBddRQyaJUhe/Qa98ebMuM+Fd4t2VdoOXvlwjjrzzfT28JRbpsl/qdSTLM0N9W 5Cp7XZL2mBFlRW46Hc6J07J+o+pzN2doLuF9+7wZY4IvDfwhTMzYX+qrEFG4gHugsA8H l9nx9EXv8Bt9MNPopzh4OQXb86iZ4V02sLeJphpTnQmhYykLhBjjdv6HR8DuLOSBbFDI GbvTVePXzvPAT1+4PdMc+ZSifaTfpfh3smSjKxg6IRe6Ikij1DStw8rNALx7a6I5zzso Lev7pfz32rox/9tOCYSmRj7Z+yzvEhHASj6ofWDjX0Wm8CwJLcPD7pdyfEmsJf/Ghika DkTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=a9NRGiq5nhs+B8ZtijmMWEf8pObEs71q+nkeZNuFE/Q=; b=aJsSRalVm0dkXQCGULR60tuz2PnlNkxhPUSjTpeUiqLzeJy6AQvz8N6VJQ4iIUvkS2 krSjzwx8RiKMmBmJePdwNCfwNI3RCE3aj4U/o+Ifi/Q0zbgrIa9YJ5oE8pc/3OnvcDNW oatMDWSD35h2fk6YN5Sx1gFZd1o/ClPJZkc2rlVf43ooMA+JjuQkVezjSQbJ4B/7FX8K LgFzlaqeWIBkpROgwH9ZXUUp8OQi+y56ay7+LQ8jAa8LE1y/ka6bLJOBBsTGNzkFoW2O VcW3YT4Y5WvN/fUyzUaVbyLn01J4Z3yb0xwnlj6ECikBwfoJrt7tSbrdHMEHSNrNOz55 XV8Q== X-Gm-Message-State: APjAAAWaXmGvtYbG9+WU3qss/ZSBNNXGqq85EIV7EuMsgdtCLVTSrtLs lnEilFytIe0esRY3TJ8eI9gRfXK6SDqOhg== X-Google-Smtp-Source: APXvYqwBqyIfFJV/VbGAfhagrPkLu/X5GVQLlz4Z7tHyH+6U1EO7Qspl3DYvqLYbHRiTeUgWQgfjjA== X-Received: by 2002:a81:2550:: with SMTP id l77mr5989423ywl.347.1582919964016; Fri, 28 Feb 2020 11:59:24 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:1528:1798:a66:1d76? ([2601:c0:c680:5cc0:1528:1798:a66:1d76]) by smtp.gmail.com with ESMTPSA id h139sm4394966ywa.35.2020.02.28.11.59.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Feb 2020 11:59:23 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: <77CBA006-9B5C-4671-BA93-153A50206F65@newclarity.net> Date: Fri, 28 Feb 2020 14:59:23 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <187930AC-002C-413D-AB50-A2F2EF4007BE@newclarity.net> References: <77CBA006-9B5C-4671-BA93-153A50206F65@newclarity.net> To: Nikita Popov X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] SimpleXMLIterator From: mike@newclarity.net (Mike Schinkel) Well, that did not work as intended... > On Feb 28, 2020, at 2:57 PM, Mike Schinkel = wrote: >=20 > OFFLIST=20 >=20 > First one want to say but thanks and kudos for all you are doing for = PHP. >=20 > Second, and so as not to hijack your thread or worse start a whole = bike shedding debate on the list, I have been wanted to ask you some = questions and I saw this as a good segue to ask your thoughts on traits = vs. interfaces vs. extends. >=20 > Simply put I have found that to use a same-named trait+interface I can = effectively achieve multiple inheritance, which is what it sounds like = would help the scenario you have below. If we had multiple inheritance = we could see much more fine-grain classes to inherit from (my = traits+interfaces are fine grained) and that could make these kind of = issues easier to deal with. >=20 > Note my thoughts here are very much influenced by Uncle Bob's blog = post "'Interface' Considered Harmful": =20 >=20 > =E2=80=A2 = https://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmfu= l.html >=20 > My questions are: =20 >=20 > 1. Internally in PHP, how different are traits implemented than = classes, and ignoring what anyone's opinion would be on if we should do = it, how technically feasible would it be to be able to "use = {class_name}" in addition to the current "use {trait_name}?" (Or better = yet "use class {class_name}") >=20 > 2. Additionally, a class with only abstract methods is effectively an = interface. How technically feasible would it be to be able to = "implements {class_name}" in addition to the current "implements = {interface_name}?" (Or better yet "implements class {class_name}") >=20 > 3. Lastly, ignoring all the above, is there a technical reason we = would not be able to allow: > =E2=80=A2 Interfaces to declare static methods? > =E2=80=A2 Traits to implement constants? > =E2=80=A2 Interfaces to declare constants? >=20 > Thank you in advance for taking the time to read, consider and reply. >=20 > -Mike >=20 > P.S. Did you see/read this which I linked to one of your Github = tickets: =20 >=20 > =E2=80=A2 https://mikeschinkel.me/2020/adding-delegation-to-php/ >=20 > Any thoughts or feedback? >=20 >=20 >=20 >> On Feb 28, 2020, at 5:59 AM, Nikita Popov = wrote: >>=20 >> Hi internals, >>=20 >> 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) >>=20 >> 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: >>=20 >> SimpleXMLElement implements IteratorAggregate >> // where SimpleXMLElement::getIterator() returns: >> SimpleXMLIterator implements Iterator >>=20 >> Of course, they would be wrong. The actual hierarchy is this: >>=20 >> SimpleXMLElement implements Traversable >> SimpleXMLIterator extends SimpleXMLElement implements Iterator >>=20 >> 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. >>=20 >> 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.) >>=20 >> 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. >>=20 >> Does that sound "reasonable"? Or rather, is there something more = reasonable >> that can be done? >>=20 >> Regards, >> Nikita >=20