CREATE TABLE temporary_products ( skuId int NOT NULL PRIMARY KEY, sku varchar(255) NOT NULL);
Category Archives: General
Disable ONLY_FULL_GROUP_BY
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
magento 2 unlock admin user
php bin/magento admin:user:unlock --help
php bin/magento admin:user:unlock USERNAME
PHP Fatal error: Uncaught Error: Cannot instantiate interface Developer.php:50
Enable Magento modules: bin/magento module:enable –all
Spaceship Operator
In PHP 7, a new feature, spaceship operator has been introduced. It is used to compare two expressions. It returns -1, 0 or 1 when first expression is respectively less than, equal to, or greater than second expression.
<?php print( 1 <=> 1);print(" "); print( 1 <=> 2);print(" "); print( 2 <=> 1);print(" "); ?>
null coalescing operator
In PHP 7, a new feature, null coalescing operator (??) has been introduced. It is used to replace the ternary operation in conjunction with isset() function. The Null coalescing operator returns its first operand if it exists and is not NULL; otherwise it returns its second operand.
magento 2 attribute add to column options
Select “Yes” to add this attribute to the list of column options in the product grid.
Closure call
Closures are anonymous functions that are declared inline and assigned to a variable. It can be used as a callback for later execution. In PHP 5 it was already possible to bind an object to the scope of the closure as if it was a method.
The “call” method is one of the PHP 7 features that was introduced to simplify the process.
<?php /** * Closure::call() */ class PHPCode { private $foo = 'PHPCode'; } $getFooCallback = function() { return $this->foo; }; echo $getFooCallback->call(new PHPCode);
Anonymous classes
Anonymous classes are useful for simple one-off objects. With anonymous classes you can define a class and instantiate an object inline.
<?php /** Anonymous classes */ $anonymousClassObject = new class { public function test() { return "PHPCodez"; } }; echo $anonymousClassObject->test();
Return type declarations
Whereas type hints ensure input consistency, return type declarations ensure output consistency.
We use a colon before the opening curly brace of a function to hint the return type.
The same strictness rules apply as with the type hints: if “strict mode” is disabled, return values that can be converted to the preferred type are allowed. If you enable “strict mode” this code will throw a type error.