Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120910 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40768 invoked from network); 15 Aug 2023 12:10:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Aug 2023 12:10:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 121531804BE for ; Tue, 15 Aug 2023 05:10:03 -0700 (PDT) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 15 Aug 2023 05:10:02 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-9923833737eso708817566b.3 for ; Tue, 15 Aug 2023 05:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692101401; x=1692706201; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=gpXgmvQihVo1gdq4ixpg2OOunowgL/4fTiYfzEqy9fo=; b=Aj96f1aqCsK7wpe9pXy6JKuC3Zx5mkYEyBC/XqZJuWFHe5NPJ3fFPfD04/kjQPPiiP 1AAqJ9u+BEBKWGTgrefRqDrTr/HJzCTMibUr3iKDKRJrTY0oRNeuaynFUDSj/+NYXjmF +nHy392+lAEAOUzq/lgqhsWO5lsNMrnd9hgQv9vlcQHqKFGXU1QuexBoDI6eyOa4qOqR MZrMqc2Ws4hVfVn0iNqmaegf38m+lI1ahR/3rafJMwPI9zkINcm5G/Xwnnoa2AIm4MlM krBxH96vsbDemRAR7dZAqwlgajBOLz3xUlv8uPthrt+RV+58fLoC1TosHKRwdA/dH6H7 p9nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692101401; x=1692706201; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gpXgmvQihVo1gdq4ixpg2OOunowgL/4fTiYfzEqy9fo=; b=PfyEhUnXt7fXfYjql9L5I5RsxcghQK2Q0H1/VAwxIkJHgKzQBF9GP/b2H+IV7dJ7+w o4me5A2e2MKN9inPb1Frk8sgIIbYgiUHAO6UCyYYzpTSr3YF14B+uWRwZ/bOs5lUedSp dx96loNu6sO7tePZicgVGGarBMv+8kvQ5NSMJarZCK2x/PKX26lHUvgL17Te4MmmCY0e vnHMBn5TBQS9o9pve+bzZkertp9Y1jLQS6lemp4WI1XnVkSY2oHyCfbMe+qy3zPbXc0n p/QI/wgVdT2GHiphHuSWuDIMxpXFMmiuu1/nom7Mw2h/KHJscD5hz1g9x+6e+aKPLtcP AMKw== X-Gm-Message-State: AOJu0YwEQFSaZ8tke5+KPqY72EsoVQzY1HWshkh9jJ7z/0WhhOjNYcoc whEqyd4TWda7tPyKp9l6OBbZC7wvgzg= X-Google-Smtp-Source: AGHT+IE9N8EN+MkwF5nmeOdqZereGi3bzCg3MHJM7xNYjhyZSVwGHBpxq4Frv4T43wy+0AxfS5zq3g== X-Received: by 2002:a17:906:2252:b0:99b:5e5f:1667 with SMTP id 18-20020a170906225200b0099b5e5f1667mr11076925ejr.15.1692101400789; Tue, 15 Aug 2023 05:10:00 -0700 (PDT) Received: from ?IPV6:2a02:1811:cc83:ee50:280e:1e36:3a00:824? (ptr-dtfv08akcem5xburtic.18120a2.ip6.access.telenet.be. [2a02:1811:cc83:ee50:280e:1e36:3a00:824]) by smtp.gmail.com with ESMTPSA id f15-20020a170906390f00b0099d45ed589csm6915801eje.125.2023.08.15.05.10.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Aug 2023 05:10:00 -0700 (PDT) Message-ID: Date: Tue, 15 Aug 2023 14:09:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: internals@lists.php.net References: <0ea64cea-a2d8-44ad-bb54-8ed321716ac8@gmail.com> <9d3b5634-4958-0351-f5a2-2b35e2ec1d3b@gmail.com> Content-Language: en-US In-Reply-To: <9d3b5634-4958-0351-f5a2-2b35e2ec1d3b@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML and JSON From: dossche.niels@gmail.com (Niels Dossche) On 14/08/2023 23:56, Rowan Tommins wrote: > On 14 August 2023 13:40:40 BST, Niels Dossche wrote: >>And you load it into simpleXML, the result of calling json_encode($the_simplexml_object) > > My usual reaction to this is "why would you take an object designed for accessing parts of an XML document, and serialise it to JSON?" Often, the answer turns out to be "because I don't understand SimpleXML objects, and have copied and pasted a weird hack to get a less useful array representation by round-tripping to JSON". > That's fair, I'm just trying to hear what people want here :-) > On the other hand, the fact that the *debug* representation of SimpleXML objects misses out some parts causes a lot of confusion, and I've actually considered the *opposite* of what you suggest - leave the JSON alone, because people will have written production code based on it, but make the debug array more descriptive of how to use the object. > I agree the debug info is lackluster at the moment. e.g. If you var_dump a simpleXML object you don't even see the name or the type. So when you're debugging it becomes a bit more difficult to see what you're working with. Similarly, a getType() method would be handy to verify what's actually "behind" the simpleXML object. > (...) > > Ultimately, I'm not that interested in trying to come up with a JSON or array representation that covers every possibility, because I think the only consistent answer would be horribly verbose - basically, describe every property that DOM would expose on each node. Probably yeah, I tried to come up with something but it was indeed verbose. > For debug output, the main concern is showing what you'll get with various styles of access in SimpleXML, so a single "@text" => "foobarbaz" would make sense; or maybe even "(string)" => "foobarbaz" and rename "@attributes" to "->attributes()" Having "->method()" might look a bit weird, at least I haven't seen something like this in other PHP extensions. Although it is more descriptive than "@attributes", because people may be led to believe you can do $simpleXML->{"@attributes"} or something like that. Adding a name and type in the output is also necessary I think. Making such changes probably requires an RFC and some bikeshedding to make sure everyone agrees on it. > > Regards, > Kind regards