Skip to content

Instantly share code, notes, and snippets.

@chajr
Last active December 16, 2018 15:22
Show Gist options
  • Save chajr/b1185e8694e018b1993679e33dd5db80 to your computer and use it in GitHub Desktop.
Save chajr/b1185e8694e018b1993679e33dd5db80 to your computer and use it in GitHub Desktop.

5.4

  • traits
  • short array syntax - $ar = []
  • function array dereferencing - foo()[0]
  • Closures support $this -
  • <?= always enabled
  • Class member access on instantiation - (new Foo)->bar()
  • binary number format - 0b001001101
  • file upload progress
  • CLI web server - php -S localhost:8000, php -S 0.0.0.0:8000
  • callable as typehint - foo(callable $var)
  • static function from expression - static function foo(){}; Class::{'foo'}()

5.5

  • Generators (yield) - Generators provide an easy way to implement simple iterators without the overhead or complexity of implementing a class that implements the Iterator interface.
  • finally - try{} catch {} finally {}
  • password_hash - password_hash($pass, $algorithm) hash_algos - return list of available algorithms
  • list in foreach - foreach ($array as list($a, $b)) {
  • empty() supports arbitrary expressions - empty(some_function())
  • array and string literal dereferencing - [1, 2, 3][0] -> 1, 'PHP'[0] -> P
  • ::class - get class name Namespace\SomeClass::class
  • OPcache
  • foreach now supports non-scalar keys
  • password_get_info - return information about hash algoritm basing on has string

5.6

  • Constant expressions: const ONE = 1; const TWO = ONE * 2; const ARR = ['a', 'b'];
  • Variadic functions via ...: function f($req, $opt = null, ...$params) {
  • Argument unpacking via ...: $operators = [2, 3]; echo add(1, ...$operators);
  • Exponentiation via: printf("2 ** 3 == %d\n", 2 ** 3);
  • use function and use const: namespace {use const Name\Space\FOO; use function Name\Space\f;
  • phpdbg: https://phpdbg.room11.org/introduction.html
  • __debugInfo(): used on var_dump().
  • gost-crypto hash algorithm
  • pgsql async support
  • hash_equals() for timing attack safe string comparison:
    $expected  = crypt('12345', '$2a$07$usesomesillystringforsalt$');
    $correct   = crypt('12345', '$2a$07$usesomesillystringforsalt$');
    $incorrect = crypt('1234',  '$2a$07$usesomesillystringforsalt$');
    
    var_dump(hash_equals($expected, $correct));
    var_dump(hash_equals($expected, $incorrect));

7.0

  • declare(strict_types=1)
  • random_bytes(10);
  • random_int(2,10)
  • Scalar type hints: function add(int $a, int $b) {
  • Return type declarations: function add(int $a, int $b): int {
  • Anonymous classes: $foo = new class {
  • The Closure::call() method: $binding = $getFooCallback->bindTo(new Foo,'Foo'); 5 -> 7 $getFooCallback->call(new Foo).PHP_EOL;
  • Generator delegation: yield from gen2();
  • Generator return expressions: $gen->getReturn()
  • The null coalesce operator: $message = $array['foo'] ?? 'not set';
  • The space ship operator: 1 <=> 1 (0 when both values are equal; -1 when the left value is less than the right value; 1 if the left value is greater than the right value)
  • Throwables (errors as exceptions): ArithmeticError, AssertionError, DivisionByZeroError, ParseError, TypeError
  • Level support for the dirname() function: echo dirname('/usr/local/bin',3).PHP_EOL;
  • The Integer division function: (10/3) 5 -> 7 intdiv(10, 3)
  • Uniform variable syntax: ${$foo['bar']['baz']} 5 -> 7 ($$foo)['bar']['baz]; $foo->{$bar['baz']} 5 -> 7($foo->$bar)['baz']; $foo->{$bar['baz']}() 5 -> 7 ($foo->$bar)['baz'](); Foo::{$bar['baz']}() 5 -> 7 (Foo::$bar)['baz']()
  • Constant arrays using define(): define('ANIMALS', [])
  • Unicode codepoint escape syntax: echo "\u{9999}" =>
  • Filtered unserialize(): unserialize($foo, ["allowed_classes" => ["MyClass", "MyClass2"]]);
  • IntlChar: echo IntlChar::charName('@') => COMMERCIAL AT; var_dump(IntlChar::ispunct('!')) => true; printf('%x', IntlChar::CODEPOINT_MAX) => 10ffff
  • Expectations: ini_set('assert.exception', 1); assert(false, new CustomError('Some error message'))
  • Group use declarations: use some\namespace\{ClassA, ClassB, ClassC as C};
  • Session options: session_start(['cache_limiter' => 'private', 'read_and_close' => true,]);
  • preg_replace_callback_array()
  • list() can always unpack objects implementing ArrayAccess
  • (clone $foo)->bar()

7.1

  • Nullable types: function testReturn(): ?string function test(?string $name)
  • Void functions: function swap(&$left, &$right): void
  • Symmetric array destructuring: list($id1, $name1) = $data[0] 5 -> 7 [$id1, $name1] = $data[0]; foreach ($data as list($id, $name)) 5 -> 7 foreach ($data as [$id, $name])
  • Class constant visibility: public const PUBLIC_CONST_B = 2;
  • iterable pseudo-type: function iterator(iterable $iter)
  • Multi catch exception handling: catch (FirstException | SecondException $e)
  • Support for keys in list(): list("id" => $id1, "name" => $name1) = $data[0] ["id" => $id1, "name" => $name1] = $data[0]
  • Support for negative string offsets: var_dump("abcdef"[-2]); var_dump(strpos("aabbcc", "b", -3));
  • Support for AEAD in ext/openssl
  • Convert callables to Closures with Closure::fromCallable(): return Closure::fromCallable([$this, 'privateFunction']);
  • Asynchronous signal handling: pcntl_async_signals(true); pcntl_signal(SIGHUP, function($sig) {echo "SIGHUP\n";}); posix_kill(posix_getpid(), SIGHUP);
  • HTTP/2 server push support in ext/curl
  • Too few arguments exception: Fatal error: Uncaught ArgumentCountError: Too few arguments to function sayHello()

7.2

  • Object type: function test(object $obj) : object
  • Extension loading by name: Shared extensions no longer require their file extension (.so for Unix or .dll for Windows)
  • Abstract method overriding: abstract class A; abstract class B extends A
  • Password hashing with Argon2: http://php.net/manual/en/ref.password.php; password_hash('password', PASSWORD_ARGON2I);
  • Extended string types for PDO: $db->quote('über', PDO::PARAM_STR | PDO::PARAM_STR_NATL); ATTR_DEFAULT_STR_PARAM PARAM_STR_CHAR
  • Additional emulated prepares debugging information for PDO
  • Support for extended operations in LDAP
  • Address Information additions to the Sockets extension
  • Parameter type widening: Parameter types from overridden methods and from interface implementations may now be omitted
  • Allow a trailing comma for grouped namespaces: use Foo\Bar\{Foo, Bar, Baz,};
  • pack() and unpack() endian support
  • Enhancements to the EXIF extension
  • SQLite3 allows writing BLOBs
  • Oracle OCI8 Transparent Application Failover Callbacks
  • Enhancements to the ZIP extension: The ZipArchive class now implements the Countable interface
  • Casting array to object change: $array = ['foo','bar','sample_key' => 'baz']; $object = (object) $array; echo $object->0; object to array ($object = new stdClass(); $object->{0} = 'foo';)
  • Output of json_decode for object as array: var_dump(json_decode($string, null, 512, JSON_OBJECT_AS_ARRAY));

7.3

  • Heredoc and Nowdoc - allow to add spaces before and after ending of block
  • Allow trailing comma in function and method calls - foo('bar', 'baz',); - Notice the trailing comma after 'baz'.
  • Option to make json_encode and json_decode throw exceptions on errors - json_decode("{", false, 512, JSON_THROW_ON_ERROR); - JsonException
  • References in list() - $arr = ['apple', 'orange']; list($a, &$b) = $arr;
  • is_countable() function
  • array_key_first() and array_key_last() - get first and last key in array
  • PCRE2 instead of PCRE in regex
  • Argon2id hash method - password_hash('password', PASSWORD_ARGON2ID, ['memory_cost' => 1<<17, 'time_cost' => 4, 'threads' => 2]);
  • Same site cookie SameSite= Lax ? Strict
  • hrtime() - return time independent of system time
  • DateTime::createFromImmutable()
  • fpm_get_status() - return state fastcgi state
  • gmp_binomial() - calculate Newton symbol
  • gmp_lcm() - calculating the least common multiple
  • gpm_perfect_power() - check that number is power perfect
  • gmp_kronecker() - calculate Kronecker symbol
  • CompileError & ParseError - two new exceptions (currently throw by token_get_all & eval)
  • MBString – full support of case-mapping & case-folding
  • compact() throw notice - when executed on undefined variable
  • instanceof - no fatal on literal - 'test' instanceof \stdClass - don't throw fatal
  • warning on continue in switch
  • ArrayAccess don't cast string $offset into integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment