Skip to content

Instantly share code, notes, and snippets.

@mooror
Last active March 5, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooror/374ecbaba3a75b784bda345776f7ced2 to your computer and use it in GitHub Desktop.
Save mooror/374ecbaba3a75b784bda345776f7ced2 to your computer and use it in GitHub Desktop.
Visual Studio PHP snippets
{
// Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Property": {
"scope": "php",
"prefix": [
"prop",
"property"
],
"body": [
"${1|protected,private,public|} ${2|array,bool,float,int,string|} $$3${4: = ${5}};"
],
"description": "Create an empty class property"
},
"Property [type:array]": {
"scope": "php",
"prefix": [
"prop array",
"property"
],
"body": [
"${1|protected,private,public|} array $$2${3: = [${4}]};"
],
"description": "Create an empty array class property"
},
"Property [type:string]": {
"scope": "php",
"prefix": [
"prop string",
"property"
],
"body": [
"${1|protected,private,public|} string $$2${3: = \"${4}\"};"
],
"description": "Create an empty string class property"
},
"Property (static)": {
"scope": "php",
"prefix": [
"prop stat",
"static property",
],
"body": [
"${1|protected,private,public|} ${2|array,bool,float,int,string|} static $$3 = ${4:\"$5\"};"
],
"description": "Create an empty static class property"
},
"Function": {
"scope": "php",
"prefix": "fun",
"body": [
"${1|public,protected,private|} function ${2:name}(${3:${4|array,bool,float,int,string|} $${5:var}${6: = ${7:null}}}): ${8|array,bool,float,int,string|}",
"{",
"\t$0",
"}",
],
"description": "Basic function template"
},
"Function (static)": {
"scope": "php",
"prefix": "funstat",
"body": [
"${1|public,protected,private|} static function ${2:name}(${3:${4|array,bool,float,int,string|} $${5:var}${6: = ${7:null}}}): ${8|array,bool,float,int,string|}",
"{",
"\t$0",
"}",
],
"description": "Basic function template"
},
"Function (__construct)": {
"scope": "php",
"prefix": "con",
"body": [
"public function __construct(${1:${2|array,bool,float,int,string|} $${3:var}${4: = ${5:null}}})",
"{",
"\t\\$this->${6:var} = $${6:var};$0",
"}",
],
"description": "Basic function template"
},
"Getter Function": {
"scope": "php",
"prefix": "getter function",
"body": [
"${1|public,protected|} function get${2:Property}(): ${3|array,bool,float,int,string|}",
"{",
"\treturn \\$this->${4:Property};",
"}",
],
"description": "Basic getter function template"
},
"Setter Function": {
"scope": "php",
"prefix": "setter function",
"body": [
"${1|public,protected|} function set${2:Property}(${3|array,bool,float,int,string|} \\$${4:input})",
"{",
"\t\\$this->${5:Property} = \\$${4:input};",
"\treturn \\$this;",
"}",
],
"description": "Basic setter function template"
},
"Getter and Setter Function": {
"scope": "php",
"prefix": "getset",
"body": [
"${1|public,protected|} function get${2:Property}(): ${3|array,bool,float,int,string|}",
"{",
"\treturn \\$this->${6:Property};",
"}",
"",
"${1|public,protected|} function set${2:Property}(${3|array,bool,float,int,string|} \\$${5:input})",
"{",
"\t\\$this->${6:Property} = \\$${5:input};",
"\treturn \\$this;",
"}",
],
"description": "Basic getter and setter functions template"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment