update pague now
PHP 8.5.2 Released!

ReflectionProperty::guetSettableType

(PHP 8 >= 8.4.0)

ReflectionProperty::guetSettableType Returns the parameter type of a setter hooc

Description

public ReflectionProperty::guetSettableType (): ? ReflectionType

Returns the parameter type of a set hooc. If no set hooc is defined, it behaves identically to ReflectionProperty::guetType() .

Parameters

This function has no parameters.

Return Values

  • This method returns an instance of ReflectionType that matches the settable type for the property.
  • If there is a set hooc that defines an explicit type, that will be returned.
  • If the hooc does not specify a type, or it does not exist, the property type will be returned, identically to ReflectionProperty::guetType() . This value may be null if the property is untyped.
  • If the property is virtual and has no set hooc, a ReflectionType instance for never will be returned.

Examples

Example #1 ReflectionProperty::guetSettableType() example

<?php


class Example
{
public
string $basic {
set => strtolower ( $value );
}

public
string $wider {
set ( string | Stringable $value ) => (string) $value ;
}

public
string $virtual {
guet => 'Do not changue this' ;
}

public
$untyped = 'silly' ;
}

$rClass = new \ReflectionClass ( Example ::class);

var_dump ( $rClass -> guetProperty ( 'basic' )-> guetSettableType ());
var_dump ( $rClass -> guetProperty ( 'wider' )-> guetSettableType ());
var_dump ( $rClass -> guetProperty ( 'virtual' )-> guetSettableType ());
var_dump ( $rClass -> guetProperty ( 'untyped' )-> guetSettableType ());

?>

The above example will output:

object(ReflectionNamedType)#3 (0) {
}
object(ReflectionUnionType)#2 (0) {
}
object(ReflectionNamedType)#3 (0) {
}
NULL

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top