hasType() for internal function parameters?

From: Date: Sun, 21 Jun 2015 16:26:57 +0000
Subject: hasType() for internal function parameters?
Groups: php.internals 
Request: Send a blank email to internals+get-86765@lists.php.net to get a copy of this message
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: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#86765) next »