Re: [PHP-DEV] [RFC] Deprecate and Remove utf8_encode and utf8_decode

2022-03-26 Thread Rowan Tommins

On 24/03/2022 11:19, Rowan Tommins wrote:
I have one issue with the wording in the RFC: While “Function 
utf8_encode is deprecated; check usage is correct and consider 
mb_convert_encoding or other replacement.” suggests to replace it, 
the part about checking the usage implies that if someone is sure 
about the correct usage it is fine to keep using utf8_encode(). But 
as the proposal wants to remove it for 9.0 I think this is somewhat 
misleading.



That's a fair point. The intention was to encourage people to look at 
whether they were using the function right in the first place, not 
blindly replace it with mb_convert_encoding, since the whole point of 
the deprecation is that they probably aren't. I'm not sure how to 
concisely say "replace with mb_convert_encoding if you actually need 
to, but maybe you can just delete this function call and your code 
will be better".



Maybe I'm trying to be "too helpful" there. Should we just use the 
generic deprecation message, and let people look up the in-depth 
explanation in the manual?


Anyone have any thoughts on that?

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] [RFC][Under discussion] Arbitrary string interpolation

2022-03-26 Thread Rowan Tommins

On 25/03/2022 14:38, Arnaud Le Blanc wrote:

I find that sprintf() is easier to read in most cases. One reason for this is
that the text is separated from the code.



Funnily enough, I find sprintf() *harder* to read for the same reason - 
particularly once there are more than two or three parameters, and more 
than a bit of punctuation between them.


A large part of that is because the placeholders are positional rather 
than named, so you have to keep track of which is which; but by the time 
you've got named placeholders, you might as well have variable 
interpolation.


As a silly example, I prefer this:

$sentence = "The {$adjectives[0]} {$adjectives[1]} {$nouns[0]} jumped 
over the {$adjectives[2]} {$nouns[1]}";


To this:

$sentence = sprintf(
   'The %s %s %s jumped over the %s %s',
   $adjectives[0],
   $adjectives[1],
   $nouns[0],
   $adjectives[2],
   $nouns[1]
);

I think that's partly a matter of taste, though, because I've definitely 
seen people happily using both styles. And there are certainly 
situations (like translation strings) where placeholders of some sort 
work better than straight interpolation.


That's why I thought it was interesting to see what other languages have 
done. While PHP and Ruby have obvious links back to Perl, many languages 
which didn't start off with string interpolation have added it in later 
versions, e.g. C#, Scala, JavaScript, Python. Clearly there were 
sufficient voices in favour in each of those communities to add it; and 
in each case, they added *expression* interpolation, not just the 
*variable* interpolation supported by Perl and PHP.


I won't be too upset if this feature doesn't get added, but I do think 
it would be a nice addition.


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php