Re: Consistent function names

From: Date: Thu, 05 Mar 2015 09:30:28 +0000
Subject: Re: Consistent function names
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-84329@lists.php.net to get a copy of this message
Le 03/03/2015 00:02, Larry Garfield a écrit :
On 3/2/15 4:50 PM, Rowan Collins wrote:
On 02/03/2015 22:36, Yasuo Ohgaki wrote:
I like scalar objects, but it does not resolve that PHP has non standard function names. It does not change old names, therefore it's impossible to resolve issue. This is the reason why I'm proposing while I like scalar object, use of namespace, etc.
Again, you're contradicting yourself here - you can't say that your mission is to change the old names, rather than offer an alternative, but then also say that the old names will stay around forever. If both names exist, that's exactly what you've created - an alternative. If we're going to have an alternative, let's come up with a creative alternative that actually has an advantage to using it, not a choice between equally cryptic names like "strripos" vs "str_ripos". Regards,
Exactly. If a PHP 7 dev has the option of: $s = strripos($s, 'a'); // works in PHP 5+ $s = str_ripos($s, 'a'); // works in PHP 7+ Really, what's the advantage of the latter? Nothing. It's an extra character to type, limits compatibility, and makes my life no easier. It's useless, and will just add to the list of things people make fun of PHP for instead of reduce it. Namespacing it is no better: $s = str\ripos($s, 'a'); // Still useless $s = php\str_ripos($s, 'a'); // Still useless Instead, compare: $s = strripos($s, 'a'); // works in PHP 5+ $s = $s->lastOccurance('a', 0, CASE_INSENSITIVE); // works in PHP 7+ Oh now we're talking! That's more self-documenting, easier to discover, makes chaining string manipulations easier to read, solves the needle/haystack issue, and reduces cholesterol. One is worth the effort of doing. The other is simply not. For subsystems that aren't clear scalars, like streams, those need a general overhaul for DX, too. Again, just doubling the number of function names adds nothing to the language but confusion, since both versions would have to live for at least the next decade. Offering a substantially better alternative does improve the language. Don't waste your time on marginal not-even-improvements. --Larry Garfield
This is, from my point of view, the direction to take. Since version 5.0, PHP is aiming to become a true OOP language. Additionally, lots of projects or frameworks are using OOP style coding (and PSR standards). What is missing today in core PHP API is scalar type hints (which I hope will be integrated soon in PHP7) and object scalars. Object scalars can bring easier management for userland developers, without the need for them to refactor their code eg: - mixing native numeric types with large numbers extensions (BCMath, GMP, or others) - define context-specific strings (managing ascii/utf8/utf16/*type in your encoding* and easy cast between them, and then handling html/sql/console escaping with decorators, ect...). I know this is a sensible point due to PHP6 unicode porting failure, but making a common OOP API for string and mbstring extensions could be an easier way to get the same functionality with less painful work As already said in this thread, Nikita Popov did an extenstion bringing this sort of functionalities (https://github.com/nikic/scalar_objects). There is also the PECL extension for Spl types (http://php.net/manual/en/book.spl-types.php) that could be integrated to the core and used as a base. Finally, this could reopen the subject about casting magic methods : https://wiki.php.net/rfc/object_cast_to_types --Grégory Planchat

« previous php.internals (#84329) next »