Skip to content

Latest commit

 

History

History

Function-invoked-like-method

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Function invoked like method

Semantic of invoking PowerShell functions and object methods is different.

Functions

  • Parentheses should not be used.
  • Parameters are space separated.
  • Parameters are positional or named.
  • There are no overloaded functions.

Methods

  • Parentheses must be used.
  • Parameters are comma separated.
  • Parameters are positional.
  • There may be overloaded methods.

It is unlikely possible to invoke an object method using function syntax by mistake, PowerShell will not recognise this as a valid call.

But it is possible to invoke a function using method syntax or just use comma by mistake for separating parameters. In such cases a function may even work without errors. But parameter may be not correct, i.e. not as designed.

Set-StrictMode -Version 2 may help to catch some of such mistakes.

Scripts