Chris Gmyr
Developer, entrepreneur, drummer, biker, dog owner, husband, and proud dad. Loves Laravel and coffee

The Latest in PHP: June 2019 Edition

06/21/2019

The June version of the "Latest in PHP" is out! Shared at our monthly TrianglePHP meeting, here are the things you need to know. If you'd like the raw slides or use this as a starting point for your own meetup, please visit our GitHub Repository.



The Latest in PHP

June 2019 Edition


Presented by

Chris Gmyr

@cmgmyr


PHP Supported Versions

  • 7.1 Security Only until Dec 1, 2019
  • 7.2 & 7.3 Active Development
  • 7.4 is underway (~Nov 2019, last 7 branch)
  • 8.0 in 2020

More Info:

  • http://php.net/supported-versions.php

PHP Releases

  • 7.1.[29-30]
  • 7.2.[18-19]
  • 7.3.[5-6]
  • 7.4.0 Alpha 1!

7.1. - 7.3. have Security and Bug fixes

More Info:

  • http://php.net/ChangeLog-7.php

PHP RFC: Arrow Functions 2.0

(Implemented in 7.4)

// before
function array_values_from_keys($arr, $keys) {
    return array_map(function ($x) use ($arr) { return $arr[$x]; }, $keys);
}

// after
function array_values_from_keys($arr, $keys) {
    return array_map(fn($x) => $arr[$x], $keys);
}

https://wiki.php.net/rfc/arrow_functions_v2


PHP RFC: Spread Operator in Array Expression

(Implemented in 7.4)

PHP has already supported argument unpacking (AKA spread operator) since 5.6. This RFC proposes to bring this feature to array expression.


$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon'];
// ['banana', 'orange', 'apple', 'pear', 'watermelon'];

https://wiki.php.net/rfc/spread_operator_for_array


PHP RFC: Nullsafe Calls

(Draft)

A new operator would be added to the language: ?->. Calling $obj?->foo(..) behaves identically to $obj->foo(..) if $obj is not null. If $obj is null, then it returns null.


function f($o) {
  return $o?->mayFail1()?->mayFail2()?->mayFail3()?->mayFail4();
}

https://wiki.php.net/rfc/nullsafe_calls


PHP RFC: Alternative "use" syntax for Closures

(Under Discussion)

https://wiki.php.net/rfc/alternative-closure-use-syntax


PHP RFC: Alternative "use" syntax for Closures


// before...

$closure = function (
    ArgumentType $argument1,
    ArgumentType $argument2,
    ArgumentType $argument3,
    ArgumentType $argument4
) use (
    $importVariable1,
    &$importVariable2,
    $importVariable3,
    &$importVariable4
): ReturnType {
    // ...
};

PHP RFC: Alternative "use" syntax for Closures


// after...

$closure = function (
    ArgumentType $argument1,
    ArgumentType $argument2,
    ArgumentType $argument3,
    ArgumentType $argument4
): ReturnType {
    use $importVariable1, &$importVariable2;
    use $importVariable3, &$importVariable4;

    // ...
};

PHP Quick Tip


levenshtein()

Calculate Levenshtein distance between two strings

$str1 = "apple";
$str2 = "appplee";

echo levenshtein($str1, $str2); // 2

https://www.php.net/manual/en/function.levenshtein.php


// input misspelled word
$input = 'carrrot';

// array of words to check against
$words  = array('apple','pineapple','banana','orange',
                'radish','carrot','pea','bean','potato');

// no shortest distance found, yet
$shortest = -1;

// loop through words to find the closest...

foreach ($words as $word) {
    // calculate the distance between the input word, and the current word
    $lev = levenshtein($input, $word);

    // check for an exact match
    if ($lev == 0) {
        $closest = $word;
        $shortest = 0;
        break;
    }

    // if this distance is less than the next found shortest
    // distance, OR if a next shortest word has not yet been found
    if ($lev <= $shortest || $shortest < 0) {
        // set the closest match, and shortest distance
        $closest  = $word;
        $shortest = $lev;
    }
}

echo "Input word: $input\n";
if ($shortest == 0) {
    echo "Exact match found: $closest\n";
} else {
    echo "Did you mean: $closest?\n";
}
---
Input word: carrrot
Did you mean: carrot?

Latest Versions

  • Laravel: 5.8.24
  • Symfony: 4.3.1
  • Drupal: 8.6.17
  • PHPStorm: 2019.1.3
  • VSCode: 1.35

PHP Conferences - July

Laracon VII July 24–25, New York, New York https://laracon.us


PHP Conferences - September

SymfonyLive Berlin 2019 September 24–27, Berlin, Germany http://berlin2019.live.symfony.com

Cascadia PHP September 19–21, Portland, OR https://cascadiaphp.com


Nomad PHP

US: Double Loop: TDD & BDD Done Right presented by Jessica Mauerhan June 20, 2019 at 06:00pm PDT

UK: The Dark Corners of the SPL presented by Omni Adams June 20, 2019 at 11:00am PDT

https://nomadphp.com/


Open Call for Papers

PHPCon Poland 2019 CfP Deadline: July 10, 2019 November 15–17, Szczyrk, Poland https://2019.phpcon.pl

PHP.Barcelona Conferenence 2019 CfP Deadline: September 30th, 2019 November 12–13, Barcelona, Spain https://php.barcelona


Upcoming regional events

All Things Open Oct 13-15, 2019 http://allthingsopen.org

Early bird going on now for $99!


Notable News & Articles


Next Month @ TrianglePHP

TDB Presented By YOU?!?!

Thursday, July 18, 6pm @ Atlantic BT

Need an Idea?

  • Testing
  • Security
  • Performance
  • Git

Have a Job/Need a Job

Who's hiring? Who's looking? What are you looking for?


Tonight @ TrianglePHP

Simple DevOps with Laravel's Forge & Envoyer

Presented By - Chris Gmyr

Thank you to Atlantic BT for hosting and refreshments!