Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Snippet.
This identifier is deterministic and will remain constant unless the
snippet is modified or moved.
Returns
Type
Description
string
file
The file in which the snippet is found.
Returns
Type
Description
string
fqn
The Snippet fully-qualified name.
Returns
Type
Description
string
line
The line number where the snippet's method or class is declared.
Note that this is NOT the line number where the snippet is declared. It
indicates the method or class which the snippet annotates.
Returns
Type
Description
int
content
The snippet content.
Returns
Type
Description
string
index
The Snippet Index
Returns
Type
Description
int
name
The snippet name
Returns
Type
Description
string
invoke
Eval the snippet and return the result.
Parameter
Name
Description
returnVar
mixed
Returns
Type
Description
mixed
addLocal
Add a local variable to make available in the snippet execution scope.
Parameters
Name
Description
name
string
The variable name
value
mixed
The variable value
Returns
Type
Description
void
addUse
Add ausestatement for a class.
Parameter
Name
Description
name
string
The class name to import.
Returns
Type
Description
void
setLine
Replace a line with new code.
Hopefully this is obvious, but be careful using this, and only use it
when no other feasible options present themselves. It's pretty easy to
make your test useless when you're overwriting the thing you are trying
to test.
This is provided for cases when a snippet relies on a global, or on
something else which can not be overridden or mocked.
Parameters
Name
Description
line
int
The line number (0-indexed) to replace.
content
string
The PHP code to inject.
Returns
Type
Description
void
insertAfterLine
Inject new code after a given line.
Hopefully this is obvious, but be careful using this, and only use it
when no other feasible options present themselves. It's pretty easy to
make your test useless when you're modifying the thing you are trying
to test.
This is provided for cases when a snippet relies on a global, or on
something else which can not be overridden or mocked.
Parameters
Name
Description
line
int
The line number (0-indexed) to write in after.
content
string
The PHP code to inject.
Returns
Type
Description
void
replace
Replace a string in the snippet with a new one.
Hopefully this is obvious, but be careful using this, and only use it
when no other feasible options present themselves. It's pretty easy to
make your test useless when you're modifying the thing you are trying
to test.
This is provided for cases when a snippet relies on a global, or on
something else which can not be overridden or mocked.
Parameters
Name
Description
old
string
The string to be replaced.
new
string
The new string to insert.
Returns
Type
Description
void
regexReplace
Find something with a regex and replace it.
Hopefully this is obvious, but be careful using this, and only use it
when no other feasible options present themselves. It's pretty easy to
make your test useless when you're modifying the thing you are trying
to test.
This is provided for cases when a snippet relies on a global, or on
something else which can not be overridden or mocked.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Snippet (1.64.2)\n\nVersion latestkeyboard_arrow_down\n\n- [1.64.2 (latest)](/php/docs/reference/cloud-core/latest/Testing.Snippet.Parser.Snippet)\n- [1.64.1](/php/docs/reference/cloud-core/1.64.1/Testing.Snippet.Parser.Snippet)\n- [1.63.0](/php/docs/reference/cloud-core/1.63.0/Testing.Snippet.Parser.Snippet)\n- [1.62.3](/php/docs/reference/cloud-core/1.62.3/Testing.Snippet.Parser.Snippet)\n- [1.61.0](/php/docs/reference/cloud-core/1.61.0/Testing.Snippet.Parser.Snippet)\n- [1.60.1](/php/docs/reference/cloud-core/1.60.1/Testing.Snippet.Parser.Snippet)\n- [1.59.1](/php/docs/reference/cloud-core/1.59.1/Testing.Snippet.Parser.Snippet)\n- [1.58.2](/php/docs/reference/cloud-core/1.58.2/Testing.Snippet.Parser.Snippet)\n- [1.53.0](/php/docs/reference/cloud-core/1.53.0/Testing.Snippet.Parser.Snippet)\n- [1.52.11](/php/docs/reference/cloud-core/1.52.11/Testing.Snippet.Parser.Snippet)\n- [1.51.2](/php/docs/reference/cloud-core/1.51.2/Testing.Snippet.Parser.Snippet)\n- [1.50.0](/php/docs/reference/cloud-core/1.50.0/Testing.Snippet.Parser.Snippet)\n- [1.49.3](/php/docs/reference/cloud-core/1.49.3/Testing.Snippet.Parser.Snippet)\n- [1.48.1](/php/docs/reference/cloud-core/1.48.1/Testing.Snippet.Parser.Snippet) \nReference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Snippet.\n\nRepresents a single code snippet\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Core \\\\ Testing \\\\ Snippet \\\\ Parser\n\nMethods\n-------\n\n### __construct\n\nCreate a snippet\n\n### identifier\n\nA unique identifier for the snippet.\n\nThis identifier is deterministic and will remain constant unless the\nsnippet is modified or moved.\n\n### file\n\nThe file in which the snippet is found.\n\n### fqn\n\nThe Snippet fully-qualified name.\n\n### line\n\nThe line number where the snippet's method or class is declared.\n\nNote that this is NOT the line number where the snippet is declared. It\nindicates the method or class which the snippet annotates.\n\n### content\n\nThe snippet content.\n\n### index\n\nThe Snippet Index\n\n### name\n\nThe snippet name\n\n### invoke\n\nEval the snippet and return the result.\n\n### addLocal\n\nAdd a local variable to make available in the snippet execution scope.\n\n### addUse\n\nAdd a `use` statement for a class.\n\n### setLine\n\nReplace a line with new code.\n\nHopefully this is obvious, but be careful using this, and only use it\nwhen no other feasible options present themselves. It's pretty easy to\nmake your test useless when you're overwriting the thing you are trying\nto test.\n\nThis is provided for cases when a snippet relies on a global, or on\nsomething else which can not be overridden or mocked.\n\n### insertAfterLine\n\nInject new code after a given line.\n\nHopefully this is obvious, but be careful using this, and only use it\nwhen no other feasible options present themselves. It's pretty easy to\nmake your test useless when you're modifying the thing you are trying\nto test.\n\nThis is provided for cases when a snippet relies on a global, or on\nsomething else which can not be overridden or mocked.\n\n### replace\n\nReplace a string in the snippet with a new one.\n\nHopefully this is obvious, but be careful using this, and only use it\nwhen no other feasible options present themselves. It's pretty easy to\nmake your test useless when you're modifying the thing you are trying\nto test.\n\nThis is provided for cases when a snippet relies on a global, or on\nsomething else which can not be overridden or mocked.\n\n### regexReplace\n\nFind something with a regex and replace it.\n\nHopefully this is obvious, but be careful using this, and only use it\nwhen no other feasible options present themselves. It's pretty easy to\nmake your test useless when you're modifying the thing you are trying\nto test.\n\nThis is provided for cases when a snippet relies on a global, or on\nsomething else which can not be overridden or mocked.\n\n### jsonSerialize\n\nSerialize to json"]]