Re: Re: [RFC] [VOTE] Random Extension 5.x

From: Date: Fri, 17 Jun 2022 18:37:28 +0000
Subject: Re: Re: [RFC] [VOTE] Random Extension 5.x
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-117992@lists.php.net to get a copy of this message
2022年6月18日(土) 3:13 Tim Düsterhus <tim@bastelstu.be>: > Hi > > On 6/17/22 19:46, Go Kudo wrote: > > I was fundamentally wrong, I understand now. > > As you said, there was no interoperability with > > pickArrayKey() in the > > first place... > > > >> stringFromAlphabet() > > > > Hmmm. I guess randomString would be better then. At the same time, it > would > > be nice to have an array version of randomArray. > > > > However, I don't want to add more methods without any thought. > > I think operations that can be done on userland should be done on > userland. > > That is why I did not implement the array_rand() function in the first > > place. > > Yes, I agree here. But I believe that "generate a string with a given > alphabet" is a very common operation that would be useful to include in > the standard library. In any case it's better to leave something out > than to implement something badly, so if you don't feel comfortable with > that, then leave it out. There will be more PHP versions after 8.2. > > For me both of these: > > ->randomString(string $alphabet, int $length) > ->stringFromAlphabet(string $alphabet, int $length) > > with the description "Return a string of $length characters selected > from the given $alphabet. Characters may be selected more than once". > > would be acceptable names. > > Best regards > Tim Düsterhus > I noticed one important thing. "String" in PHP means binary, and operating on multibyte characters often causes problems. Although I rarely deal with multibyte characters in my work, this can probably be a big problem for Japanese PHP users like myself. To work around this, the mbstring extension must be used properly, but since mbstring is not built-in, it is appropriate to implement it in userland. For the reasons stated above, we will abandon the addition of new methods. sorry. str_shuffle() and shuffleString() already have similar problems. So perhaps an alternative method name for str_shuffle() might be bytesShuffle() instead of stringShuffle(). Regards Go Kudo

« previous php.internals (#117992) next »