Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP 7.3 && Laravel 5.7

PHP 7.3 && Laravel 5.7

A short summary of new things in PHP and its favorite framework.

Christian Leo-Pernold

October 23, 2018
Tweet

More Decks by Christian Leo-Pernold

Other Decks in Technology

Transcript

  1. PHP 7.3 && Laravel 5.7
    PHP 7.3 && Laravel 5.7
    1 / 21

    View Slide

  2. Christian Leo-Pernold
    @mazedlx
    https://github.com/mazedlx
    https://mazedlx.net
    2 / 21

    View Slide

  3. Agenda
    Agenda
    Awesome Laravel 5.7 awesomeness!
    New PHP 7.3 features!
    3 / 21

    View Slide

  4. Laravel 5.7
    Laravel 5.7
    Email Verification
    Email Verification
    Dump Server
    Dump Server
    Improved Error Messages
    Improved Error Messages
    Beautiful Error Pages
    Beautiful Error Pages
    4 / 21

    View Slide

  5. Email Verification
    Email Verification
    // create_users_table migration
    $table->timestamp('email_verified_at')->nullable();
    namespace
    namespace App
    App;
    use
    use Illuminate
    Illuminate\Notifications
    Notifications\Notifiable
    Notifiable;
    use
    use Illuminate
    Illuminate\Contracts
    Contracts\Auth
    Auth\MustVerifyEmail
    MustVerifyEmail;
    use
    use Illuminate
    Illuminate\Foundation
    Foundation\Auth
    Auth\User
    User as
    as Authenticatable
    Authenticatable;
    class
    class User
    User extends
    extends Authenticatable
    Authenticatable implements
    implements MustVerifyEmail
    MustVerifyEmail
    {
    use
    use Notifiable
    Notifiable;
    // ...
    }
    5 / 21

    View Slide

  6. Email Verification
    Email Verification
    Auth::routes(['verify' => true
    true]);
    // This will add the following new routes
    // GET|HEAD email/resend
    // GET|HEAD email/verify
    // GET|HEAD email/verify/{id}
    6 / 21

    View Slide

  7. Email Verification
    Email Verification
    Route::get('/profile', function
    function () {
    // Only for verified users
    })->middleware('verified');
    7 / 21

    View Slide

  8. Dump Server
    Dump Server
    $ php artisan dump-server
    Laravel Var Dump Server
    =======================
    [OK] Server listening on tcp://127.0.0.1:9912
    // Quit the server with CONTROL-C
    8 / 21

    View Slide

  9. Improved Error Messages
    Improved Error Messages
    $user = App\User::forst();
    // 5.6: Method Illuminate\Database\Query\Builder::forst does not exist.
    // 5.7: Call to undefined method App\User::forst();
    9 / 21

    View Slide

  10. Beautiful Error Pages
    Beautiful Error Pages
    10 / 21

    View Slide

  11. Beautiful Error Pages
    Beautiful Error Pages
    11 / 21

    View Slide

  12. Beautiful Error Pages
    Beautiful Error Pages
    12 / 21

    View Slide

  13. Beautiful Error Pages
    Beautiful Error Pages
    13 / 21

    View Slide

  14. Beautiful Error Pages
    Beautiful Error Pages
    403
    404
    419 - session has expired
    429 - too many requests
    500
    503
    Thank you, @steveschoger
    14 / 21

    View Slide

  15. PHP 7.3
    PHP 7.3
    Array functions
    Array functions
    High Resolution Time
    High Resolution Time
    PCRE2
    PCRE2
    json_encode/json_decode Exceptions
    json_encode/json_decode Exceptions
    15 / 21

    View Slide

  16. Array functions
    Array functions
    $arr = [
    'bob' => 1,
    'jane' => 2,
    'john' => 3
    ];
    var_dump(array_key_first($arr)); // bob
    var_dump(array_key_last($arr)); // john
    16 / 21

    View Slide

  17. Array functions
    Array functions
    $arr = 'this is not an array!';
    count($arr); // Warning count(): Parameter must be an array or an object that i
    if
    if (is_countable($arr)) {
    count($arr);
    }
    17 / 21

    View Slide

  18. High Resolution Time
    High Resolution Time
    $time = hrtime($getAsNumber = false
    false);
    18 / 21

    View Slide

  19. PCRE2
    PCRE2
    $matches = [];
    // throws compilation failed error
    preg_match('/[\w-.]+/', 'some -- words-and hyphens -', $matches);
    // ok
    preg_match('/[\w\-.]+/', 'some -- words-and hyphens -', $matches);
    19 / 21

    View Slide

  20. json_encode / json_decode
    json_encode / json_decode
    throw exception on errors
    throw exception on errors
    try
    try {
    json_decode("{", $assoc = false
    false, $depth = 512, JSON_THROW_ON_ERROR);
    } catch
    catch (\JsonException $e) {
    echo
    echo $exception->getMessage(); // "Syntax error"
    }
    20 / 21

    View Slide

  21. Slides can be found at speakerdeck.com/mazedlx
    21 / 21

    View Slide

  22. View Slide