Php
cotrTypeCheck
PHP Type Check
gettype(${1:variable})
cotrTypeCompare
PHP Type Comparison
// Check if two variables have the same type:if (gettype(${1:variable1}) === gettype(${2:variable2})) { // Your code here}
cotrTypesBool
PHP Boolean Type
bool
cotrThrow
PHP Throw Exception
throw new ${1:Exception}('${2:Your message here}');
cotrInfo
PHP Info
Typing: Dynamically typedParadigm: Multi-paradigm: imperative, object-oriented, procedural, reflectiveCompilation: InterpretedConcurrency: Supports multi-threading with extensions like pthreads, but traditionally single-threaded
cotrTypesString
PHP String Type
string
cotrVarTyped
PHP Create Typed Variable
// PHP is a dynamically typed language, which means that by default there is no need to specify the type// of a variable, as this will be determined at runtime.// However, it is possible to statically type some aspect of the language via the use of type declarations.${1:Type} $${2:myVar} = $3;
cotrTypeConvert
PHP Type Conversion
// PHP Type Conversion:
// Implicit conversions (PHP performs automatically):// - Can be unpredictable, especially with loose equality (==).
// Explicit conversions (using casts):// - (Type)variable // C-style cast
// Conversion functions:// - intval(variable) // Converts to integer// - floatval(variable) // Converts to float// - strval(variable) // Converts to string// - boolval(variable) // Converts to boolean
// Note:// - Be aware of implicit conversions and use explicit conversions when necessary for clarity and control.
cotrVarMultiString
PHP Create Multi-Line String Variable
$${1:myString} = <<<EOT${2:Your string here}EOT;
cotrFuncArgs
PHP Function Args
// In PHP, functions can have arguments with default values.function ${2:myFunction}(${3:$arg1}, ${4:$arg2} = '${5:defaultVal}') { ${6:// Your code here}}
cotrComment
PHP Comment
// ${1:Your comment here}
cotrTypesDate
PHP Date Type
DateTime
cotrTypesDynamic
PHP Dynamic Type
// PHP is a dynamically typed language.
cotrVarBool
PHP Create Boolean Variable
$${1:myBool} = ${2:true};
cotrVarList
PHP Create Array Variable
$${1:myArray} = [${2:items}];
cotrForLoop
PHP For Loop
for ($${1:i} = 0; $1 < ${2:10}; $1++) { // Your code here}
cotrForEachLoop
PHP For Each Loop
foreach ($${1:iterable} as $${2:item}) { ${3:// Your code here}}
cotrFuncArrow
PHP Arrow Function
$${2:myFunction} = fn(${3:parameters}) => ${4:// Your code here};
cotrTypesBoolFalse
PHP Boolean False
false
cotrVarStatic
PHP Static Variable
static $${1:myStaticVar} = $2;
cotrVarNum
PHP Create Float Variable
$${1:myFloat} = ${2:0.0};
cotrGenList
PHP Generate Array
$${1:myArray} = range(${2:0}, ${3:10});
cotrGenMap
PHP Generate Map
$${1:myMap} = array_combine(range(${2:0}, ${3:10}), range(${4:0}, ${5:10}));
cotrDoWhileLoop
PHP Do While Loop
do { ${1:// Your code here}} while ($${2:condition});
cotrFunc
PHP Function
function ${2:myFunction}(${3:parameters}) { ${4:// Your code here}}
cotrTypesInt
PHP Integer Type
int
cotrTypesNum
PHP Float Type
float
cotrTryCatch
PHP Try Catch
try { ${1:// Your code here}} catch (${2:Exception} $${3:e}) { ${4:// Your code here}}
cotrNotEqual
PHP Not Equal To
!=
cotrVarInt
PHP Create Integer Variable
$${1:myInt} = ${2:0};
cotrEqual
PHP Equal To
==
cotrSwitch
PHP Switch Statement
switch ($${1:variable}) { case ${2:value1}: ${3:// Your code here} break; case ${4:value2}: ${5:// Your code here} break; default: ${6:// Your code here}}
cotrFuncLambda
PHP Lambda Function
function (${1:parameters}) => ${2:expression}
cotrVar
PHP Create Variable
$${1:myVar} = $2;
cotrPrintMulti
PHP Print Multi
echo <<<EOT${1:Line 1}${2:Line 2}${3:Line 3}EOT;
cotrFuncArgsNamed
PHP Function Named Args
// Note: PHP does not support named arguments in function definitions.
cotrFuncAnon
PHP Anonymous Function
$${2:myFunction} = function(${3:parameters}) { ${4:// Your code here}};
cotrEnum
PHP Enum
abstract class ${1:MyEnum} { const ${2:VALUE1} = ${3:0}; const ${4:VALUE2} = ${5:1}; // Add more values here}
cotrIf
PHP If Statement
if (${1:condition}) { ${2:// Your code here}}
cotrVarDate
PHP Create Date Variable
$${1:myDate} = new DateTime('${2:Y-m-d}');
cotrIfElse
PHP If Else Statement
if (${1:condition}) { ${2:// Your code here}} else { ${3:// Your code here}}
cotrTernary
PHP Ternary Operator
${1:condition} ? ${2:trueValue} : ${3:falseValue}
cotrClass
PHP Class
class ${1:MyClass} { ${2:// Your code here}}
cotrOperatorsBool
PHP Boolean Operators
// PHP Boolean Operators// Logical AND: && or and// Logical OR: || or or// Logical NOT: !// Equality: ==// Identity (Strict Equality): ===// Inequality: !=// Non-identity (Strict Inequality): !==// Greater than: >// Less than: <// Greater than or equal to: >=// Less than or equal to: <=
cotrTypes
PHP Types
$BLOCK_COMMENT_STARTPHP is a dynamically typed language.
Types in PHP include:- int: Integer- float: Floating-point number- string: A sequence of characters- bool: Boolean- array: An ordered map- object: An instance of a class- resource: Holds a reference to an external resource- NULL: Represents a variable with no value- callable: A type that can be called, such as a function or a method- iterable: A type that can be iterated over, such as an array or an object implementing the Traversable interface- mixed: Indicates that a parameter may accept multiple (but not all) types- void: Indicates that a function does not return a value- never: Indicates that a function does not return normally (it either throws an exception or terminates the script)$BLOCK_COMMENT_END
cotrNull
PHP Null Type
null
cotrTypesList
PHP List Type
// In PHP, indexed arrays are used as lists.
cotrVarNullable
PHP Create Nullable Variable
${1:Type}? $${2:myVar} = $3;
cotrVarString
PHP Create String Variable
$${1:myString} = '${2:Your string here}';
cotrCommentMulti
PHP Multi-Line Comment
/* * ${1:Your comment here} */
cotrEntry
PHP Entry Point
// PHP Entry Point// To run this program, use: `php filename.php`
<?phpecho 'Hello, World!';?>
cotrVarSyntax
Variable Declaration Syntax
// PHP Variable Declaration Syntax:
// - $: (Scope: Global or Function)// - Variables start with a dollar sign.// - Can be reassigned and redeclared within their scope.// - Use with caution due to potential scoping issues.
// - const: (Scope: Global)// - Cannot be reassigned or redeclared.// - Use for values that should remain constant.
// Note:// - PHP does not have a direct equivalent to 'let'.// - Use '$' for most variable declarations.// - Use 'const' for values that are known at compile time.
cotrPrint
PHP Print
print('${1:Your message here}');
cotrStructure
PHP Project Structure (High-Level)
// Recommended High-Level PHP Project Structure:
// - public/// - Contains the entry point of the application (e.g., index.php) and static files.
// - src/// - Contains the PHP source files and classes.// - Organize by feature or component.
// - vendor/// - Contains third-party dependencies managed by Composer.
// - config/// - Configuration files for the application.
// - templates/// - View templates for the application (if using a traditional MVC structure).
// - resources/// - Other resources like language files, not directly accessed by the public.
// - tests/// - Unit and functional tests for the application.
// - storage/// - Used for logs, cache, and other generated files.
// Note:// - This structure can be adapted based on the framework or libraries you are using.// - Ensure that the public directory is the document root for the web server to secure application internals.
cotrOperators
PHP Mathematical Operators
// PHP Mathematical Operators// Addition: +// Subtraction: -// Multiplication: *// Exponentiation: **// Division: /// Modulus (Remainder): %// Increment: ++// Decrement: --// Assignment: =// Addition assignment: +=// Subtraction assignment: -=// Multiplication assignment: *=// Division assignment: /=// Modulus assignment: %=
cotrTypesBoolTrue
PHP Boolean True
true
cotrInterpolate
PHP Interpolate String
'Your string here \${${1:variable}}'
cotrConcat
PHP Concatenate Strings
'${1:string1}' . '${2:string2}'
cotrVarMap
PHP Create Map Variable
$${1:myMap} = [${2:key} => ${3:value}];
cotrConst
PHP Create Constant
const $${1:myConst} = $2;
cotrTypesMap
PHP Map Type
// In PHP, associative arrays are used as maps.
cotrWhileLoop
PHP While Loop
while ($${1:condition}) { ${2:// Your code here}}
cotrFuncSyntax
PHP Function Syntax
// PHP Function Syntax// Basic function: function functionName(parameters) { ... }// Function with arguments: function functionName($arg1, $arg2, ...) { ... }// Note: PHP does not support named arguments in function definitions.