Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108791 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72855 invoked from network); 28 Feb 2020 21:39:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Feb 2020 21:39:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E36651804D7 for ; Fri, 28 Feb 2020 11:57:18 -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,HTML_MESSAGE,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-f48.google.com (mail-yw1-f48.google.com [209.85.161.48]) (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:57:18 -0800 (PST) Received: by mail-yw1-f48.google.com with SMTP id n127so4466807ywd.9 for ; Fri, 28 Feb 2020 11:57:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=D5lhKjEiNtrzPiVOZ2K5RN9dzU83UeBTT8QeYlO6vPw=; b=LNmCamavVHojLN+LhhRSddKuGvMwvEUgBI2nFOVVQVCmEMgg0lIhf6tVeoD7R7domB x/3DqpYeCWnFVnunOX66Vx36VOkAd8+tMjnSQxPS7LSgt27Rh+va3AmvrJhbIdSK1lLd Nt+zIreuDOV0UggP8arum22OJrGn7Fyml+hVcnJ2Kdva1CMDFGRArgqumkFEw11x4gQs I8iv3hQWwjz2qa00TVoD9TjjsTVZDBnEo3csZxZqt9y24EUBvleMcgd7tUt8cNjj445W KLiEkjBFm2jXI9t7d3F8DHDBfnkLr7P89MJ0QLf8Cbr6F8m/zmsM9B6j3JJkuvVMzaha e9aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=D5lhKjEiNtrzPiVOZ2K5RN9dzU83UeBTT8QeYlO6vPw=; b=BiCbaYj7QXV+fXbeMSjlzxnGLLOl6uCT6RJSLoBL2BWwQCFrv9JyQhqUyWoFOR4bi6 2pyLIkE7rQQaWrkN9FhlCZ+Wj1mjorXwPTV/OTdZVGcIxtNMQ4jGfIvU344I0/3ESJlo wyj1NT26Wm2brTu9iIbMBviXQoEnGyQTYy7WHDcMN4ftn5cfaMOVttveSQ+ljRGNm30R bSjHQzQl67U5aI3l/nqsOobv3UZHqeX+zlV91W9nRIZlPLyEoVdxq8zkPN5UqraTnTft O6IrHaVkhUE6SafGZ6c/zYAbqDyQFXCKjkKJg2FaAGBXo40tpy/Z1Q0zXL0UQRDuTBrt 0p4w== X-Gm-Message-State: APjAAAUyMKzOrp4TIHvuYsQepIPsiMY/ractn5GnziGinZN/mGWvlzLk CfI8gYccB4IisAF5ShXZCSoNNQ== X-Google-Smtp-Source: APXvYqw5y6X4eBgHt1hXZAu7RZ+NeOa369mzNx3uTJm1XwtgcZsiLNANC6m3Yis6f+BXwWMTD4tFdw== X-Received: by 2002:a81:7994:: with SMTP id u142mr6056081ywc.419.1582919834387; Fri, 28 Feb 2020 11:57:14 -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 w132sm4356121ywc.51.2020.02.28.11.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Feb 2020 11:57:12 -0800 (PST) Message-ID: <77CBA006-9B5C-4671-BA93-153A50206F65@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_98ED74F4-EC8B-4093-AF29-9DA11FC5B97F" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Fri, 28 Feb 2020 14:57:11 -0500 In-Reply-To: Cc: PHP internals To: Nikita Popov References: X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] SimpleXMLIterator From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_98ED74F4-EC8B-4093-AF29-9DA11FC5B97F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii OFFLIST=20 First one want to say but thanks and kudos for all you are doing for = PHP. 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. 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. Note my thoughts here are very much influenced by Uncle Bob's blog post = "'Interface' Considered Harmful": =20 = https://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmfu= l.html My questions are: =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}") 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}") 3. Lastly, ignoring all the above, is there a technical reason we would = not be able to allow: Interfaces to declare static methods? Traits to implement constants? Interfaces to declare constants? Thank you in advance for taking the time to read, consider and reply. -Mike P.S. Did you see/read this which I linked to one of your Github tickets: = =20 https://mikeschinkel.me/2020/adding-delegation-to-php/ Any thoughts or feedback? > 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 --Apple-Mail=_98ED74F4-EC8B-4093-AF29-9DA11FC5B97F--