Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122571 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 241061AD8F6 for ; Tue, 5 Mar 2024 17:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1709660464; bh=aKAhOdKIh+FzAOpXzMxck4fFGdz1w3K2cUeNKMIBlAM=; h=In-Reply-To:References:Date:From:To:Subject:From; b=JxL5kWs83YS9ZgP64sLbRMnMGpIfHoBfkDnn/E9ChWjPNBLgvl57SIfKrX4qE57ZV OSk2nAF4OQlbczFpm/Uerk6d+qBAYS6AplFIFJMrXdf5bW/8aPcBJWnP750KI491xD 9jx/hnTPvm5bpkajg7BPgr0z6gGfZCogVoAiBYAa2eWBmNvlS5eQ3tl/eg8DApylOT YGl1FcZUCvK9X7OhQW8PHsYUbUA8AWF4CtJcVo+/u6j7ehghthgruWswgY0C840Z1s pbfks1Pn0TZLIpbKw/2TshdKa/SAWBiBVLsqAo2nRCFlffC4FaMp0ZBs2+5v8azPm2 89a2/cNzZtp4A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F38A4180047 for ; Tue, 5 Mar 2024 17:41:02 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 17:41:02 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 8910D32001C6 for ; Tue, 5 Mar 2024 12:40:48 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 05 Mar 2024 12:40:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1709660448; x=1709746848; bh=EptcbkAgsvmyoFceEbTP5 t2TQCaqaczgAh82wskyk4k=; b=UbH5VqcFIWc4MpP9H4kM/NO7d80REdtKUujFu VMvLioPct+s4zmwynyvO6M0kulQdsl9Yj6RpQAFay3y+j6xHIOTWsK9SN6q71jOA KoebME/TUETuQ3GTpYcqhfpvAywrIJVEKCiMUcov4Q2KZU+c+TMwgTy2TsaFn6qf rp2UEg+Ef5dQw3/E6HqXaYGTJXFiIsYIeFsHH9IzpOFcn1i/O4zjGXZC+PzvVLr9 cYjM4vEYSxcW4IlYdZHz4UvhsEjNRVMbBzGTBUqQv/Zi3wCVF97tjU0Zcglyl1lO q6LxnupaJ1SvLT3Y3peEjBl3rsS848bzqAvpNLzHjjovXWO9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709660448; x= 1709746848; bh=EptcbkAgsvmyoFceEbTP5t2TQCaqaczgAh82wskyk4k=; b=K 3dORUKyBQzrObUdgZB5zffzsVhqO8LC+JLeCzBoS8SwSwignZnkhtttcdfKrpgSc PirTXi+q7SllzfCvuX6jBuZ/y2bddXNmuthTEurAWzlGYuJZq0tRRDNQgoD0jIqz kXxTh2mOVqInJQg2FJmD2DrLU+hDJUaprKSvr9aanIVJDVuzoBT1KmD0yk36lwBX IERHGV248vxHqXMWcUrtxWjljQg2po5gvjLpvvNcsvLrKsSWsWMr2TZgtDB4PdzN 3cdnSJsYRbqaYhmDo9S9jo2BR0NMOstJQ4jqXGK+D43Tg1s2jks1yHZfiBs0dR91 /J8rQn3OgLLmDjSua+DQA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrheelgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhephfektdffgffhkeeiudehvdehfefgfeehuefgvdel teetkeetgfetjeeiledtleeknecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehg rghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id C21601700098; Tue, 5 Mar 2024 12:40:47 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-208-g3f1d79aedb-fm-20240301.002-g3f1d79ae Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <51122d7e-f218-4243-bbb8-dd59de2165b4@app.fastmail.com> In-Reply-To: References: Date: Tue, 05 Mar 2024 17:40:26 +0000 To: "php internals" Subject: Re: [PHP-DEV] [Discussion] grapheme cluster for str_split function Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Mar 5, 2024, at 7:25 AM, youkidearitai wrote: > 2024=E5=B9=B43=E6=9C=885=E6=97=A5(=E7=81=AB) 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 =3D 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 instea= d 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 u= sing 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. Right now, the best "standard" error handling mechanism available is exc= eptions. false (or null) can very easily lead to incorrectly using that= value as though it were valid, when it's not, which will sometimes caus= e a fatal error and sometimes cause a security leak. =20 If the input value cannot be logically processed, that's an exception. = (Or Error, perhaps.) --Larry Garfield