Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122574 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 60D8C1AD8F6 for ; Tue, 5 Mar 2024 20:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1709670000; bh=iDThizagn5Wo5atVGzBRLIFR4XAx5+YMaKWsWNonEdc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=UFlZ0vHQG5UsbIUNm1JfrHfeBToS4fC75habIH1rPg+b/FfX4iybuTRIe4dJQBnQz id+zLLcg9u0JQ03fuENMdycbBkPB3dJbLHGJ/PvDsICo7jHx4+S2RzBfcSIPCESPPB 2eHlCGVGVCgsQurJO0SV6ReqafA/cgCOXbGql0yFa483DLHEw3UxFdhdgv0yTO3vIE 2+rRZunOQqwXQ0xBQawS54zWz5RKIJwC+4YXz/rcXRAPhp1F3BmkoIPODEGC7kfJ3j TN3zivBGuyoQw2OnONNWoUyHam5KPNbwoYyy3VptO2RaK+q2ruYSoX5r8xJBRnlHMk NhEKBc4G34o8w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4223D18003E for ; Tue, 5 Mar 2024 20:19:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 5 Mar 2024 20:19:58 +0000 (UTC) Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-412f1fc5613so1932735e9.2 for ; Tue, 05 Mar 2024 12:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709669985; x=1710274785; darn=lists.php.net; 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=JGdphByPspMcCcEm70WGqR4OpfAuBkoVlYHZSxN/eyc=; b=NU3ZBrR/IogXsaOoCJywJrmHCUB2azEfiKwKQ5VAfRucmC0fkaOKoG9kJkvLHRQhGp twoTsyKmn8dhHC9DoPWT7YaLl1jnx69r4Y8h4/SiqaaInAnaRIeXFbjVKGGjJPCuu9oM Kf2OWDb0dG9dQhP6K9A2MjQMar476Hi17WSFHh53d55ngl4Wq1l3/3ncsgUPz23pASwG ivwMgXwNL4RL/v6aoS7GUMiMZBK4VGYx1hBNW/1LA9h9lVbSQA2XJM0YtCDD/BOHyG+t wGcsASqlUmUf0jQ2wAem2UThXAe6XoAsjBViv1/EiN93DJzw5DHv8xz4qcgmoRJIY8y5 L+AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709669985; x=1710274785; 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=JGdphByPspMcCcEm70WGqR4OpfAuBkoVlYHZSxN/eyc=; b=iwdYUKZhm/D5vCeOZlCLlTMTORbZnCpRDB8jalM4llPIPyi80wU8xu3erHqFaaV+Ug y3Ww6jJ5+5fm0Z2g+nYW4T+HgfRx2lRniCyXhol+07hf34aWNBxQ7Hy+gUzLo7kFCQLq zlgUISZSdoQtq+bYuxQvDhOCsQvHSY0qav4IEgM7zDpQF04az87b9jQXTQ4roKmogvt0 v/AIQYEW9DwytuWuu5JYXLhGyUsJxZLgafgHShHnETCj6w6cvhdgSsAssgPs3/GRh1bf /JDAt4KhxNGrTMu5Gd5USa2INvcpJBbc7fzAM2fxTMvMR5DwqhEu/uXe2F04dF6HIrJR i+hg== X-Gm-Message-State: AOJu0YwMiTPvXbJsT/zxKomkvh++n6LAlQOeiqhtbpIQ29vLM6BrwsAn A+ScxQZB54l7ftOUSGiuNpX2g2gcU+8dgOszM92JhX82vvROGPBcLW6nlnyY X-Google-Smtp-Source: AGHT+IF9Vub9FhSHVvdW3YoGcoC340yF0rTWd9dahB+pd/RQtx/HRm7nCbcwOTdfWkxSdh6KS3U9Lg== X-Received: by 2002:a05:600c:3b89:b0:412:f196:1065 with SMTP id n9-20020a05600c3b8900b00412f1961065mr510324wms.10.1709669984844; Tue, 05 Mar 2024 12:19:44 -0800 (PST) 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 bg14-20020a05600c3c8e00b004122b7a680dsm19118523wmb.21.2024.03.05.12.19.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 12:19:44 -0800 (PST) Message-ID: <5817daaf-813c-430e-a12f-32908d1f7ec7@gmail.com> Date: Tue, 5 Mar 2024 21:19:44 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Discussion] grapheme cluster for str_split function To: internals@lists.php.net References: <51122d7e-f218-4243-bbb8-dd59de2165b4@app.fastmail.com> Content-Language: en-US In-Reply-To: <51122d7e-f218-4243-bbb8-dd59de2165b4@app.fastmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: dossche.niels@gmail.com (Niels Dossche) Hi Larry Hi Yuya So first of all, I meant the error handling in cases like these: https://github.com/php/php-src/pull/13580/files#diff-b8fe038d9d7539694593978bea5605f38dde4bcb6a016865130590e45e23202eR852-R860 The implementation still returns NULL here, so the signature is still incorrect. Either it should return false to match the other functions, or throw something and not return a value. On 05/03/2024 18:40, Larry Garfield wrote: > On Tue, Mar 5, 2024, at 7:25 AM, youkidearitai wrote: >> 2024年3月5日(火) 5:52 Niels Dossche : >>> >>> Hi Yuya >>> >>> This sounds useful. >>> >>> I do have a question about the function signature: >>> function grapheme_str_split(string $string, int $length = 1): array {} >>> >>> This always returns an array. >>> However, looking at your PR it seems you return NULL on failure, but the return type in the signature isn't nullable. >>> Also, from a quick look, it seems other functions return false instead of null on failure. So perhaps the return type should be array|false. >>> >>> What do you think? :) >>> >>> Kind regards >>> Niels >>> >>> On 03/03/2024 00:21, youkidearitai wrote: >>>> Hi, Internals >>>> >>>> I noticed PHP does not have grapheme cluster for str_split function., >>>> Until now, you had to use the PCRE function's \X. >>>> >>>> Therefore, I try create `grapheme_str_split` function. >>>> https://github.com/php/php-src/pull/13580 >>>> It is possible to convert array per emoji and variation selectors using ICU. >>>> >>>> If it's fine, I'll create an RFC. >>>> >>>> Regards >>>> Yuya >>>> >> >> Hi, Niels >> >> Thank you for your comment. >> Indeed, returns false is make sense. >> >> Therefore, I changed to returns false when invalid UTF-8 strings. >> >> Regards >> Yuya > > Many legacy functions return false on error, but that is widely regarded as bad design. Please do not continue bad design. I agree that returning false on error isn't ideal for exceptional cases, that's what exceptions are for. Looking at the other grapheme functions makes me wonder though how consistent this would be, especially w.r.t. intl_get_error_*() and intl_error_name(). > > Right now, the best "standard" error handling mechanism available is exceptions. false (or null) can very easily lead to incorrectly using that value as though it were valid, when it's not, which will sometimes cause a fatal error and sometimes cause a security leak. > > If the input value cannot be logically processed, that's an exception. (Or Error, perhaps.) > > --Larry Garfield Kind regards Niels