Re: [PHP-DEV] [Concept] declare(strict_identifiers=1)

"[email protected]" <[email protected]>
Newsgroups gmane.comp.php.devel
Message-ID <AMBP191MB2886F843261ACD913043F713CEAD2@AMBP191MB2886.EURP191.PROD.OUTLOOK.COM>
 > If this is so rarely seen in the wild (something that should be verified
 > with more than 250 packages), why make it an option?  Just plan that 
PHP 9
 > will enforce UTF-8-or-GTFO rules on identifiers, Symfony updates one
 > oddball class, and we move on with life.  99.99% of developers won't
 > notice anything happened.

I ran it: the top 5,000 Packagist packages by downloads, 4,863 of them
resolvable and non-empty, 520,802 PHP files, 2.4 GB. Raw scanner output,
per-identifier CSVs and the corpus manifest are in the repository.

It is not one oddball class.

1,447 non-ASCII identifiers across 25 packages. 1,312 of them -- 91 % --
are in markrogoyski/math-php, and they are neither fixtures nor accidents.
They are variable names in src/, and they spell the formula:

     $n! = self::factorial($n);
     $∑  = 0;
     protected $d₁;
     $π  = \M_PI;
     $│∑│      = $∑->det();
     $√⟮2π⟯ᵏ│∑│ = \sqrt((2 * $π) ** $k * $│∑│);

1,247 of the 1,312 are T_VARIABLE. 888 of them would stop compiling: the
offenders are U+27EE/U+27EF mathematical flattened parentheses, subscript
and superscript digits, U+2211 summation, U+2212 minus. None of those is
in XID_Continue.

So the honest answer to "99.99 % won't notice" is that one library would
notice 888 times, and its author chose that style deliberately and has
shipped it for years.

The rest of the picture argues the other way, though, and I would rather
give you both halves.

Outside math-php there are 135 non-ASCII identifiers, and only 25 fail --
15 of which are one test file in hoa/console with arrow characters in
method names (case_move_↑, U+2191). Everything else already conforms:

   mjaschen/phpgeo     22, all conforming: $φ, $λ, $sinλ, $cos2σM in
                       src/Bearing/BearingEllipsoidal.php -- Vincenty
                       geodesy, Greek letters only, no symbols
   tracy/tracy         14, all conforming: $ʟ_tmp, $ʟ_tag in Latte
                       templates, U+029F as a namespace prefix so internal
                       variables cannot collide with user ones
   wsdltophp/...       44, all conforming: setСубъектРФ, ApiАдресРФ --
                       generated accessors over a Russian WSDL schema,
                       where the names come from the schema

And across all 520,802 files, zero identifiers are not in NFC.

So the cost of making this mandatory is specific and nameable rather than a
long tail: it outlaws mathematical symbol notation in identifiers. Two
packages do that. Everything else in the top 5,000 that uses non-ASCII
identifiers already satisfies the rule and would not notice.

That may still be the right call -- "PHP identifiers are letters, not
notation" is a defensible position and I am not arguing against it. But it
is a decision to withdraw something that works today, not a cleanup of an
oddity, and I would rather the list took it with the number in front of it.

One correction to something I said in the other subthread: I told Chris
there was not one identifier mixing Latin with Cyrillic or Greek. At 250
packages that was true. At 5,000 there are 41 outside math-php, and they
are benign -- a code generator putting an ASCII "set" in front of a
Cyrillic schema element. My mixed-script metric flags the script pair, not
the risk, and I should have said so.

Regards,
Luca
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.