Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105139 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62700 invoked from network); 8 Apr 2019 11:05:35 -0000 Received: from unknown (HELO mail-it1-f178.google.com) (209.85.166.178) by pb1.pair.com with SMTP; 8 Apr 2019 11:05:35 -0000 Received: by mail-it1-f178.google.com with SMTP id q14so19299905itk.0 for ; Mon, 08 Apr 2019 01:02:10 -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=z1+C/VBkckNgUvJNRZTN21Ke6XTLyvth1oM5NGXEDJ0=; b=ef4jTq0nZ7NQgRxA30FApVzWxZHtChjKB3dedfctsW3lW4cAIVtQIebAOYusRn0F8p qfgbH8geYLc1rzaUZnv6/KAU2Rz4Ch0/YrioOTNNI7xR8bFRsV7Vp2dy/pfgR0mFjkuO AhUhRcDwCuGSTuH6mquq9CoH5t7NPWynZvYvyqLfTe2Iv6oXiFjpRPGRIywwwfZ8Wkzz JSUW3VRlHr1ru9ajjl8wfzDPLiuhqRuXVlRPIKs7RJiysNEaUfhSDOa7j1pyuELTb/vF jP5Y1R7eTOQyyPm+m6aCRcqDJXTHaGOrv9ggeTTeVIbHmyeezPR/RcZvAaDMIxhB52OT HfYw== 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=z1+C/VBkckNgUvJNRZTN21Ke6XTLyvth1oM5NGXEDJ0=; b=QzdGDEP5BIyD6WsFnALQ5Q4QEQmfL/LUEYqp9glDDlusQ1oRN1aNNKjmJFlXIG1qcw CO1T2kgehqNGkPR02lifFasrwJ8YsNYnNuAnVxsbYIPPWvcCl2NYq9bjk5oJllOz+H4f 2Zp9yARkNHxvbPf12JVMI2lG0SqdZZNTpzshiUSv4t5pLLrXjl0txryvjwFaY17yTTSb Ear49kBcXt85NUxpTynlJRUi4+4nIm12qGqL+rogLl20fCKYkdXhsPNwGGzfVhQzvycQ 6fV1lx43CilykHJE2GpXIkeFrBIBz+x1LoJmXOZw5gKbr/GpX9HB9pdyHaRQhKhJqHp/ AIKg== X-Gm-Message-State: APjAAAVbbEt8PY5gVYpZhkXE4KeBqHNZyMrxiikLurGLXq0yoylne8GM sx1xMFnO7DZgUbWgXgE8fRb24MAD21rF+qoLnXA= X-Google-Smtp-Source: APXvYqxJnqxKhK+kBpL956SJnNd5zRphFUxxx4JjDs848gJEtsz8l7169PNc2B20hnlLrQ5u0wZRxs/4C+vuH37BvBI= X-Received: by 2002:a24:3945:: with SMTP id l66mr12338828ita.125.1554710530125; Mon, 08 Apr 2019 01:02:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 8 Apr 2019 10:01:53 +0200 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000e075560586004012" Subject: Re: [PHP-DEV] Allow number_format() have three args From: nikita.ppv@gmail.com (Nikita Popov) --000000000000e075560586004012 Content-Type: text/plain; charset="UTF-8" On Mon, Apr 8, 2019 at 9:51 AM David Rodrigues wrote: > Currently number_format() could accept one, two or four args. If three args > is passed then you will receive "wrong parameter count for number_format()" > error (ArgumentCountError). > > It have four parameters: float $number, int $decimals, string $dec_point > and string $thousands_sep. > > * If one arg is passed, then $decimals = 0 and $thousands_sep = ",". > * If two args is passed, then $dec_point = "." and $thousands_sep = ",". > * If four args is passed, then it will respect given args; > > There some cases where we just don't need a $thousands_sep, so I suggest to > accept three args with $thousands_sep = '' (and not a comma). > > It will works fine for the doc ( > https://www.php.net/manual/en/function.number-format.php) example: > > // english notation without thousands separator > $english_format_number = number_format($number, 2, '.', ''); // Currently > $english_format_number = number_format($number, 2, '.'); // After > // 1234.57 (same result) > > The fourth parameter will change "the behavior" if compared with the > another original cases, but it will happen because there is no reason to > use three args if you pretends to keep the comma as fourth arg once that > normally you will use or "." or "," as decimal separator. > > * If you pretends to use dot + comma, just use two args; > * If you pretends to use comma + dot, just use four args; > * If you pretends to use dot + nothing, use three args; > * If you pretends to use comma + nothing, use three args This seems very confusing. Despite the somewhat convoluted description in the docs, the way the function currently works is with the number_format(float $number, int $decimals = 0, string $dec_point = ".", string $thousands_sep = ",") signature and all defaults behaving as usual, plus an explicit check to prohibit three arguments. I think it would make sense to allow three arguments to make this function behave more normally, but in this case "," should stay the default of the thousands separator. Changing a default value based on the number of arguments passed would be a major WTF moment, imho. I don't think think the confusion is worth saving an "" argument. Regards, Nikita --000000000000e075560586004012--