Search notes:

PowerShell: Loosly and strongly typed variables

Each object and by implication each variable has a type. In PowerShell, a variable is by default loosly typed, but can be explicitly defined to be strongly typed.
A strongly typed variable always refers to objects of the same type: the type with which the variable was defined. In contrast, the types of the objects a loosly typed variable refers to might change during the existence of the variable.
A loosly typed variable springs into existence when a value is assigned to an undefined variable:
$aVariable = 99
A strongle typed variable is created by using the [type] $var = … construct when a value is assigned to a variable for the first time:
[int] anInteger = 42
When a value of a different type is assigned to a strongly typed variable, PowerShell tries to cast the value to the type of the strongly typed variable. This is demonstrated by the following script:
[int] $anInteger = 42
      $aVariable = 99

$anInteger.GetType().FullName # System.Int32
$aVariable.GetType().FullName # System.Int32

$anInteger = "17"
$aVariable = "32"

$anInteger.GetType().FullName # System.Int32
$aVariable.GetType().FullName # System.String
Github repository about-PowerShell, path: /language/variable/typed-untyped.ps1

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1759562276, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/variable/loosly-and-strongly-typed(57): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78