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. 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
  2. Email Verification Email Verification <?php <?php // create_users_table migration $table->timestamp('email_verified_at')->nullable();

    <?php <?php 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
  3. Email Verification Email Verification <?php <?php 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
  4. Email Verification Email Verification <?php <?php Route::get('/profile', function function ()

    { // Only for verified users })->middleware('verified'); 7 / 21
  5. 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
  6. Improved Error Messages Improved Error Messages <?php <?php $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
  7. Beautiful Error Pages Beautiful Error Pages 403 404 419 -

    session has expired 429 - too many requests 500 503 Thank you, @steveschoger 14 / 21
  8. 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
  9. Array functions Array functions <?php <?php $arr = [ 'bob'

    => 1, 'jane' => 2, 'john' => 3 ]; var_dump(array_key_first($arr)); // bob var_dump(array_key_last($arr)); // john 16 / 21
  10. Array functions Array functions <?php <?php $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
  11. High Resolution Time High Resolution Time <?php <?php $time =

    hrtime($getAsNumber = false false); 18 / 21
  12. PCRE2 PCRE2 <?php <?php $matches = []; // throws compilation

    failed error preg_match('/[\w-.]+/', 'some -- words-and hyphens -', $matches); // ok preg_match('/[\w\-.]+/', 'some -- words-and hyphens -', $matches); 19 / 21
  13. json_encode / json_decode json_encode / json_decode throw exception on errors

    throw exception on errors <?php <?php 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