Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114725 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55379 invoked from network); 4 Jun 2021 06:11:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jun 2021 06:11:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6831E180211 for ; Thu, 3 Jun 2021 23:25:00 -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,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 ; Thu, 3 Jun 2021 23:24:59 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id f2so8063881wri.11 for ; Thu, 03 Jun 2021 23:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld.be; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=P/B8L8Zi8Ps0Qm8QizrJexR9YzMoJebnE6ZcC0a0hy0=; b=lWN4gT7pCRLhjWtcYWvvM/jTwf/oxRri0I+F/JXF0OLcWJdWMGsgh/GPjiqN28m3d6 sg3WOeoktLxa7pHiT9z4sohG3e9ysbfaN2qVA7+jv1Ujo4HlAe9m244RDOHaRpeomxBp rbx2J9aLuODT8EiyfAH8sFoP3Vs5vDCHDj4+tjtkFU+GSyFzAkbIZ69pr+zMFhwu7Y7U 0XBTt/ASd9JmHAlrUh2TUsY+uncY7RMNg2SMIV1y+yQMFdLpmmJr+TgvwQGxY1T4e7eL vkpmjgQx6fpIOBjN+dtwU3ChsDmtA54eztCffaOh1hhTBG0PUgTr2Y8dC7l/hYNYJqlt b2jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=P/B8L8Zi8Ps0Qm8QizrJexR9YzMoJebnE6ZcC0a0hy0=; b=eA1L1+8PkQcbj45ykXFBquEOPAxSD82cMuWMHhsZ7HwPhkdZ7CETWYS9EpyRNr4uzm M2dm7A9qeruP3DzTwlFYzzgtnrIv4MartpJBT7MWstyl0E7EVpzVsFb45+OeVfvwRp1C uGUqO0Q8RfzAqZFuUEZXx46B79iiEZ4RbHn2htgFIeEg7PFhRGR9nHBYFOoq5MzcjA8W of/T+4UmuEGsx4qI8ndE/nYOLjMsmXGdhxkbxdfUSQfhcqpX5qqoT3jiiGt6FhnDiBSF FgTKIkcAxkHCFVLmJdi0WjyQP/wxbVy5hzVw0J7+HlXdBlXgM7paI5rpkHh3aIgooM8S Qn8A== X-Gm-Message-State: AOAM530RbVfCF+A1T1QIhrSp3BrS7zkLM4lgTUBib2Kbh4dwGnEoJRM3 EKyx4xXRnwNTM0/TQkFLYr0FB9kc5eYeVg== X-Google-Smtp-Source: ABdhPJwzORI4efN8erYWjJr0z1m4dkpynym5H0RCW/BY//n+WAjNjyApnhtxsAQclIcFBhGHKLO1iQ== X-Received: by 2002:adf:d4cc:: with SMTP id w12mr2046912wrk.216.1622787894179; Thu, 03 Jun 2021 23:24:54 -0700 (PDT) Received: from ?IPv6:2a02:168:4b6e:0:a47b:8b41:d08d:909? ([2a02:168:4b6e:0:a47b:8b41:d08d:909]) by smtp.gmail.com with ESMTPSA id v16sm4958514wrr.6.2021.06.03.23.24.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Jun 2021 23:24:53 -0700 (PDT) To: internals@lists.php.net References: <06f92428-a426-0afa-72ab-053e224a87ce@seld.be> <4c8f7ea1-6112-8046-846c-b701ab707752@gmail.com> <1008623e-faed-aa39-3b58-48d37d306e5d@gmail.com> Message-ID: <5b1ee897-d01a-9636-c3c0-c435f7708f66@seld.be> Date: Fri, 4 Jun 2021 08:24:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <1008623e-faed-aa39-3b58-48d37d306e5d@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [PHP-DEV] json_encode indent parameter From: j.boggiano@seld.be (Jordi Boggiano) On 03/06/2021 18:03, Timon de Groot wrote: > On 3-6-2021 17:53, Ayesh Karunaratne wrote: >> Hi Timon, >> Thank you for this RFC. I think the `string|int $indent` approach is >> great 🚀! >> >> Reading the PR, it looks like `$indent=0` is essentially turning off >> pretty-print, which I think is intuitive. > Basically, yes. With `$indent=0`, no indentation will take place but > new lines will still be added. >> Do you plan to add any sort of validation on negative integers? >> Perhaps throw a `\ValueError` exception on $indent < 0? > > Good question. Personally I'd prefer clamping $indent to 0 when it > reaches below 0. But I'd like > to hear about what other particpants think about such behavior. > IMO the JS spec is quite reasonable there, and I would say copying it 1:1 would be fine:     If this is a Number, it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.     If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used. Best, Jordi -- Jordi Boggiano @seldaek - https://seld.be