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

Typed PHP

Typed PHP

Strings, arrays and numbers are second-class citizens in PHP-land. This talk describes how they can be extended to work like objects, and how clean and consistent APIs can be introduced so that you can be proud of your PHP code again.

Christopher Pitt

December 19, 2014
Tweet

More Decks by Christopher Pitt

Other Decks in Programming

Transcript

  1. Underscores and abbreviations ⌁ 98 string functions ⌁ 30 with

    underscores, 68 without ⌁ 55 with abbreviations, 43 without
  2. Return values preg_match returns 1 if a pattern matches a

    given subject, 0 if a pattern does not match a given subject. Or false if there was an error.
  3. Return values preg_match returns 1 if a pattern matches a

    given subject, 0 if a pattern does not match a given subject. Or false if there was an error.
  4. Return values Oh, and by the way: "This function may

    return Boolean FALSE, but may also return a non- Boolean value which evaluates to FALSE..."
  5. Return values Oh, and by the way: "This function may

    return Boolean FALSE, but may also return a non- Boolean value which evaluates to FALSE..."
  6. Boxing $string = new StringObject("hello world"); $string->value(); // "hello world"

    function value(StringObject $string) { return $string->value(); }
  7. Optional types $user = User::find(1); if ($user !== null) $address

    = $user->address(); if ($address !== null) $city = $address->city(); if ($city !== null) $forecast = $city->forecast(); print "Your forecast: " . $forecast;
  8. Optional types $user = User::find(1); if ($user !== null) $address

    = $user->address(); if ($address !== null) $city = $address->city(); if ($city !== null) $forecast = $city->forecast(); print "Your forecast: " . $forecast;
  9. Learning more ⌁ Anthony Ferrara @ircmaxell ⌁ Igor Wiedler @igorwhiletrue

    ⌁ Christopher Pitt @assertchris ⌁ joind.in/talk/view/13094