Is it deliberate that we are not providing the parameter types for
internal functions via reflection? It seems inconsistent:

    <?php
    declare(strict_types=1);
    function ustrlen(string $str) { }
    $param_ustrlen = (new
ReflectionFunction('ustrlen'))->getParameters()[0];
    $param_strlen = (new ReflectionFunction('strlen'))->getParameters()[0];

    echo "$param_ustrlen (".$param_ustrlen->hasType().")\n";
    echo "$param_strlen (".$param_strlen->hasType().")\n";

    try {
        ustrlen(1);
    } catch (TypeError $e) {
        echo $e->getMessage()."\n";
    }

    try {
        strlen(1);
    } catch (TypeError $e) {
        echo $e->getMessage()."\n";
    }

The output is:

Parameter #0 [ <required> string $str ] (1)
Parameter #0 [ <required> $str ] ()
Argument 1 passed to ustrlen() must be of the type string, integer
given, called in /home/rasmus/prop.php on line 11
strlen() expects parameter 1 to be string, integer given

That is, in both cases a TypeError exception is raised because the type
of the parameter is incorrect. But hasType() on the internal function
parameter claims there is no type even though there obviously is one.

-Rasmus

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to