Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104691 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86984 invoked from network); 13 Mar 2019 09:00:24 -0000 Received: from unknown (HELO mail-wm1-f67.google.com) (209.85.128.67) by pb1.pair.com with SMTP; 13 Mar 2019 09:00:24 -0000 Received: by mail-wm1-f67.google.com with SMTP id n19so530741wmi.1 for ; Tue, 12 Mar 2019 22:50:28 -0700 (PDT) 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 :cc; bh=wjX33zmppIC2Yq3hNlvYm/I0W92GH2oOdOo456P7ZHs=; b=GaLxVoWUYPqKNlcQxibWazgfbdDq4B2aSTvtIp+Lq74DsYd/AEEeGj5abi6BwR5Qmb IaWJ5ARHiI+yz8xkUnJiukOKbonI2WcMORn3aJpsvXuZvu5qR9RzNKe9nYl6aGXGSgXS LufVA6QN5Lo+RI5KlTgyv7Vr/NEVi03YJX8dZnHewVEylKccM5c6T5C9eCnJVxcvfq2y E+hPWFG+78J4JD0bQxZRqcI3zaaap4g3GYA0WlUQJsqVUJ7XFUTGW42TrBLqJRnjUKmS SpLXVcsrs+Qpc7zK2c7zTrBqdEY843dxAe9Bsxb5NDDp/60pnNcp3KRumgs3uCH/d2/o xorw== 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:cc; bh=wjX33zmppIC2Yq3hNlvYm/I0W92GH2oOdOo456P7ZHs=; b=T9GYVtzZuysVy7mpri/Yq9rZyXffyaoN6LHWSfSbcMbUI/vZW/qgvyC9rau/REZTdF mRC38Ry2fgwuqPr2y2GzQIKAcLxybdanqjdxdhZ8gwrICHaEf4/UCauKIWUzJHdrdfDI asUrN4zHVavrztOszyPp0IHBMo8WvY8ugqxJUK3S8zr2vOg2GtxfvRVAkjJNNK1ltOSZ n405lSxMS5cHEHvbokXTvy6XldQDSdvO1T+nwpRAt3Xfmotkkn9ZpUo/J8Pm2efPqXgF LpAXUYOKPBczfJm9y/BswwT/b6H3PPc/Jthw8lMQacfKt+pQQWYLAueY8rdgWdj9yRWh apxw== X-Gm-Message-State: APjAAAVYoHsbB+Cjz43AuxIMm9ZCdLHl8NY7uVAuA748KhQnj3y8pL7E 6XjosPvC7xNTYhvnj2NFPUZC2EiK21cC/MpfSP0= X-Google-Smtp-Source: APXvYqwISdmWtIaGesUg5BAY8XMFB4dDQ/QdJa66uM2QO668jbgyygs+WrXRHLj7qtLC4TqdskM4/k9OEbTmcVSLy/k= X-Received: by 2002:a1c:7008:: with SMTP id l8mr800048wmc.63.1552456227791; Tue, 12 Mar 2019 22:50:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 13 Mar 2019 12:50:15 +0700 Message-ID: To: Benjamin Eberlei , Rob Richards Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000fcaa760583f3613d" Subject: Re: [PHP-DEV] On fixing DOMNameSpaceNode and DOM NS API Inconsistency Problems From: pierre.php@gmail.com (Pierre Joye) --000000000000fcaa760583f3613d Content-Type: text/plain; charset="UTF-8" Hi, Only adding Rob just in case :) best, On Wed, Mar 13, 2019, 5:54 AM Benjamin Eberlei wrote: > Hi everyone, > > While looking for things to work on in php-src my friend Thomas pointed me > to a peculiar special case in ext/dom that leads to massive inconsistency > problems in the API. > > There is an undocumented class DOMNameSpaceNode that gets returned from > DOMElement::getAttributeNode(NS) if you select an attribute that represents > a namespace (xmlns). This special case is intentionally handled in the > code, contrary to Pythons DOM Extension which doesn't do this and contrary > to the DOM Specification, which does not have a special DOMNameSpaceNode. > Its all DOMAttr. > > Problematically DOMNameSpaceNode doesn't extend from DOMAttr, you cannot > pass this class to DOMElement::removeAttributeNode(DOMAttr $attr): > > Fatal error: Uncaught TypeError: Argument 1 passed to > DOMElement::removeAttributeNode() must be an instance of DOMAttr, instance > of DOMNameSpaceNode given > > Code example here: https://3v4l.org/jkC5s > > In addition the DOMNameSpaceNode renames all properties compared to > DOMAttr, clearly violating the interface documented here > http://php.net/manual/de/domelement.getattributenode.php > > Two potential fixes come to mind: > > 1. Have DOMNameSpaceNode extend DOMAttr - maybe this was the originally > intended behavior, becuase the properties are all named differently? > 2. Have DOMElement::removeAttributeNode accept also a DOMNameSpaceNode > (3.) Remove the non standard DOMNameSpaceNode class and use a DOMAttr > instead > > I think approach #1 is the right one from a BC perspective and also fixing > the DOM API to be more consistent with the standard. > > But I am also not opposed to #3 in the longer term, looking at Github > DOMNamespaceNode in the open source world is only used for one apc test, in > PHP Compat and when dumping it in Symfony Var Dumper. I imagine its more > deeply used in closed source code working deeply with XML. > > The second problem that this inconsistency creates is > DOMElement::removeAttributeNS($namespaceUri, $localName). When you want to > use it to remove a namespace attribute (xmlns). By default the xmlns > namespace has the uri http://www.w3.org/2000/xmlns/. Hence removing > xmlns:$name namespace would expected to be: > > DOMElement::removeAttributeNS("http://www.w3.org/2000/xmlns/", "foo") // > removes xmlns:foo > > But thats not how it works, there is special code implemented that requires > you to pick the URI from xmlns:foo value: > > > > DOMElement::removeAttributeNS("urn:foo", "foo"); > > But if your node has an attribute in this namespace with the same name, it > gets removed as well: > > > > Would incorrectly become this, removing 2 attributes: > > > > This is a bug that cannot be fixed in a BC way. I have no clue how to fix > this completly broken behavior in a good way. I propose to break BC here > and requiring "http://www.w3.org/2000/xmlns/" as namespaceURI from PHP 8.0 > to delete a namespace (xmlns) attribute. > > Should I put both issues into an RFC or are these rather bugs that can be > fixed without an RFC? > > greetings > Benjamin > --000000000000fcaa760583f3613d--