When using the ReflectionParameter
class to loop through native PHP class __construct()
parameters, I've noticed that the type-hints of the parameters in the docs aren't matching up to what I'm getting using the class methods.
For example the DateTime
object:
$reflector = new ReflectionClass('DateTime');
$constructor = $reflector->getConstructor();
if ($constructorParams = $constructor->getParameters()) {
foreach ($constructorParams as $i => $param) {
var_dump($param->getClass());
}
}
This outputs:
null
null
But according to the docs the class description is:
public DateTime::__construct ([ string $time = "now" [, DateTimeZone $timezone = NULL ]] )
Shouldn't the $timezone
parameter have a type-hint of DateTimeZone
? Or is the parameter not actually type-hinted, and rather the docs are just telling you what should be passed in?
Also, when outputting the names they are different as well: var_dump($param->name)
outputs:
time
object
However if I were to do a reflection on PDO
, a var dump of the names outputs correctly like in the docs:
dsn
username
passwd
options
new DateTime(null)
andnew DateTime(2018)
without any errors or warnings, that seems to be the case.$time
does, but$timezone
shows up asobject
. The PDO object shows up accurately though. Checking something likeArrayObject
shows up almost 100% accurate too with the exception of$flags
actually beingar_flags