Skip to content

Instantly share code, notes, and snippets.

@aczietlow
Last active August 22, 2016 18:25
Show Gist options
  • Save aczietlow/5b2b7f228d8da0bad3a3 to your computer and use it in GitHub Desktop.
Save aczietlow/5b2b7f228d8da0bad3a3 to your computer and use it in GitHub Desktop.
PHP[world] 2015 session notes

PHP[World] 2015

TL;DR

  1. PHP 7 is amazing
  2. Drupal 8, Symfony 3, Magento 2, Laravel 3, PHPUnit 5, Zend Framework 3 are all dropping by the end of the year
  • Really need to brush up on my OOP skills, all the cool kids are doing it
  1. Open source is continuing to grow in government (including Drupal)
  2. Literally everyone here has a CI process (build tool, automated testing, automated deployment)
  • Vagrant/docker
  1. Be a good community member, be a human being; don't be a dick
  2. WordPress is huge (25% of top 10 million sites) and they're starting to catch up technologically.
  • WordPress Rest API
  • Composer
  • big kid toys
  1. Drupal is well respected in the PHP community
  • As is MediaCurrent

Day 1

A year in U.S. digital Services

Andrew Nacin

U.S. Digital Service - High level government team for assessing government software projects. Andrew shares what they've accomplished and what he's learned in his year spent with USDS

  • e.g. fixing healthcare.gov
  • Bring best practices into government software projects
    • Actual best practices, like from the private sector
  • WordPress powers 25% of top 10 million sites
  • Created a "playbook" for successful development process
    • Building successful teams
    • Flexible hosting environments
    • Defaulting to open source
      • Being more open about software development. i.e. use github, share contributions back, be more transparent
  • A strong focus on real time monitoring in government now
    • Dashboards that execs can access to get real time feedback on software products
  • Worked to help the team building ELIS - (ELectronic Immigration System)
    • Bringing technological solution to immgration process
    • Currently tons and tons of paper and giant mainframes
      • long process, costly process
  • Mandated all projects in gov use https
  • Pushing open source
  • Cobolt is still a challenge
    • All the cobalt engineers are reaching retirement age

Actually Modernizing WordPress Development

Eugene Cook

Bringing "modern development" practices to WP development

  • Frustations in WP Development
    • No code seperation, not MVC or DI
    • So many plugins, hard to manage
    • Lack of abstraction
    • repetition
    • No 3rd party standards
    • Not great developer experience
  • 12 factor - concepts of a well developed projects
  • Challenges
    • dev on boarding
    • dependency management
    • config management
    • Build process
  • Bedrock
    • Modularly built developed WP using many best practices
      • Composer based
      • library & code separation
      • autoloading
      • build process
  • Composer
    • composer.json
    • wpackagist.org - WordPress Themes and Plugins
    • private repos with composer
      • toran
        • Acts a proxy b/n composer and VCS
        • bitbucket, gitlabs, github enterprise
        • Can be used to automate update process
      • satis
  • Deployment tool

PHP 7 Crash Course

Colin O'Dell

Scalar Type Hints

  • Weak
    • Can pass variables as typed parameters where conversions are possible.
      • int can become a float
      • object with __toString() can be converted to string

Strong

declare(strict_type=1);

Return Type Declaration

function getAuthor(): UserInterface {
    return 'Chris'
  }

getAuthor();

// Error b/c you attempted to the return value is not instance of UserInterface

  • Can allow NULL return Type
  • RFCs are open to allow for void and null return types

Combined coparison operator

"Space ship operator"

<==>

Returns 0 if both expresiions are equal 1 if left is greater -1 if left is lesser

  • Can be used to compare arrays
    • compares index by index.
      • Compares arrayA[0] to arrayB[0]
      • find first difference and returns value or compares all indexes until all are found equal and it returns 0
  • Use case: sorting arrays using usort() or other array sort functions

Null coalesce operator

??

Allows for checking for null value in comparison ternaries

$value = $_GET['date'] ?: $date //E_NOTICE

$value = $_GET['date'] ?? $date

Unicode Codepoint Escape Syntax

(0x2603)

$snowman = "\u{2603}";

Anonymous classes

Similar use case to anonymous functions but with classes

$httpClient->setLogger(new class implements loggerInterface {
  file_put_contents($file);
  });
  • Doesn't require adding a file, namespacing, injecting it into the DI container
  • Can quickly create mock objects when unit testing

User-land CSPRING API

  • random_bytes(int $lenth)
  • random_int(int $min, int $max)
  • Creates cryptographically secure randomly generated numbers
  • replaces rand()
  • Doesn't require an extension
  • Supports system level random generating functionality

Changes and Improvements

  • Performances
    • Fuck yea!
    • php 7 is on par with hhvm now
    • PHP ng (next generation initiative)
  • Uniform Variable Syntax
    • Now longer parsing variables from right to left
      • Allow for things like $$foo()['bar']()
    • Can cause backwards compatiable
      • $foo->bar['baz']; now is interpreted as ($foo->bar)['baz'];
  • semi reserved words
    • can now use reserved words as properties and method names
      • PHP 7 can detect context when it encounters key words
  • Error Handling and Exception
    • Fatal and recoverable errors are now thrown like exceptions
    • Not pokemon
      • Do NOT try to catch them all
  • Unserialize method
    • Deals with security vulnerabilities when unserializing data

Depreciated and removed

Test code in php 5.6 for deprecated notices

  • Depreciation of PHP4 contructors
  • deprecation of salt option for password_hash()
  • Removal of previously-deprecated features
    • instaniate objects by reference
    • php ini comments
      • # old comments
      • ; new comments
    • Removal of alt php tags
      • <% // %>
  • Reclassification of E_STRICT notices
    • ex some E_STRICT notices are now E_DEPRECATED

Installing PHP7

Brace yourself, PHP 7 is scheduled for release on Nov 26

  • Ubuntu
    • There's a ppa with precompiled PHP7
  • pre compiled
    • php7.zend.com
      • docker file
      • bin
  • mac
    • phpbrew

Upgrade guide

Leading an Open Source projects

Tessa Mero

  • Joomla comes from "Jumla" which is Swahili for "All Together"
  • Key Components for leading an open source community
    • Community and Leadership
    • Documentation and Transparency
    • Code of Coducts are a thing
      • Don't be a dick
      • Now we've documented that we've said "dont be a dick"
      • Don't be a dick
    • Other people are people, treat them like people

Symfony 3: Hot of the griddle

Andreas Hucks @meandmymonkey

  • Symfony Versions
    • standard
      • 8 Months of bug Supports
    • LTS
      • 2 years of Support
  • Uses semmantic versioning
  • Dropped backwards compatibility and depreciated code
  • If you're using 2.8 and aren't using depreciated code migration to 3.0 should be trivial
  • 2.8
    • Twig 2
    • Internal refactoring
    • Dropped PHP template Support
    • Dropped support for ACLs
    • Added a lot more support for marking units as depreciated
    • more awesome more better
  • PRs must pass Travis and appveyer
    • appveyor like travis but with a windows box. WHAT WHAT!?!?!
  • Deprecation Detector
    • triggers E_USER_DEPRECATED from @deprecated annotations
  • New in 3.0
    • PSR 7
      • Request and Response standard
    • LDAP Component

Intermediate OOP

David Stockton @dstockto http://www.slideshare.net/dstockto/intermediate-oop-in-php-55282686

tl;dr

  • magic methods are useful when useful
  • polymorphism - Classes to follow, inherit, extend an agreed upon standard
  • cohesion - do one thing, and do it well
  • coupling - decouple all of the things
  • Learning the SPL already. It's fucking awesome. Be more awesome
    • Seriously

Magic methods

  • __contruct()
  • __destruct()
    • Called when object goes out of scope
  • __call()
    • called when object calls inaccessible methods
  • __callStatic()
  • __get()
    • called when reading a property that's not in scope
    • $value = $bar->madeUpProperty;
  • __set()
    • called when a value is set to a property that doesn't exist on the instance on teh class
  • __isset
    • called when isset is called on a property on an object
  • __unset
    • Use cases
      • with a magic setter:
        • Can create a class that doesn't allow dynamically adding properties
        • Can enforce a naming convention for dynamically set properties
  • __Sleep & __Wakeup
    • Called on serialize() and unserialize()
    • __sleep() to close connections, to clean up
    • __wakeup use to reestablish connections
    • somethings aren't serializable in PHP: closures
  • __toString()
    • retrieve a string representation of object
  • __clone()
    • by default clone is shallow
      • Will duplicate scalar primary types, but not objects
        • Uses the same instance of objects
  • __invoke()
    • allows an object to be used like a function. (makes it callable)
  • __autoload()
    • Don't use __autoload instead use spl_autoload_register
  • debuginfo()
    • new in php 5.6
    • controls output in var_dump()

Polymorphism

Something somthing rectangles and squares

  • Interfaces
  • Abstract Classes

Observer pattern

  • subject communicate state changes to dependencies (observers)

Dependency Injection

  • Allows for loose coupling of objects
  • Dependencies can get passed as parameters to classes to create new objects that have instances of other objects

High cohesion

  • "If you have to use the word 'And' when describing a method, class, or package, then it's probably doing to much."

Prefer composition over inheritance

  • Inheritance is not the only way to extend functionality of a class
  • Allow other classes to do work and communicate results
  • Delicate work

Day 2

Hello PSR-7

HTTP Message Interface

  • Sets standards for Request and Response objects
  • Accepted May 18 2015
  • Immutable request objects
  • Reusable web layer b/n frameworks
  • stackphp.com
  • 7 Interfaces
    • Stream
    • Message
    • Request
    • Response
    • ...
  • Supported frameworks
    • Slim 3
    • Zend Expressive
      • zend micro-framework
    • radar
      • Using PSR-7 and ADR pattern
    • Nimble Framework

Lessons Learned from Laravel

Taylor Otwell @taylorotwell

  • Superpower Syntax
    • empower your users, make people's lives easier
    • Be opinionated
    • laravel elixir is gulp as a service
    • api code is like user experience
  • Travel light
    • less code is more better
    • "Kent Beck Design rules"
    • Iteration is a thing. dont over architect problems you don't have yet
    • Traveling light is easier to document
  • Scratch the itches
    • Build anything
    • It's better than the 95% that don't post anything
    • Laravel homestead - vagrant packaged box
    • don't try to be all things to all people
  • Make your community positive and passionate

Debugging in Drupal 8

Kalpana Goel @kalpanagoel

  • Slides - bit.ly/debugging-d8

  • uncomment debug line in settings.php $config['system.logging']['error_level'] = 'verbose';

  • Sweet lord settings.php ships with commented out code for a local.settings.php

  • Settings directive for many dealing with caching

  • Twig debug

    • have to enable debugging in Twig
    • Enables {{dump()}}
    • Enables autoreload
    • Can print loaded template files
  • Twig cache

    • Don't touch it
    • - Scott, twig maintainer
  • new stuff from devel

    • kint($vars);
    • king_trace();
    • web-profile module
      • Based on the profile component from symfony
      • Timeline module
        • How long the symfony components took to process a request
      • Request info
        • Shows configured routes
      • All the things
        • Bitchin'
  • Console

    • scaffolding
    • some debugging
  • profiling

    • xhprof
    • blackfire
  • container.debug

Day 3

The state of PHPUnit

Sebastian Bergmann @s_bergmann

  • 2 month release cycle
  • Latest is phpUnit 5.x
  • backwards compatability breaks b/c of PHP 7
  • Dropped some support for some unused assertions
    • assertSelectCount()
  • small tests @small annotation
    • No longer allowed to touch I/O
    • throws risky PHPUnit Exception
  • teamcity logger (for phpstorm)
    • Helps phpstorm continue to be able to communicate with new releases of PHPUnit
      • Has been a problem in the past
  • Can implement PHPUnit warnings
  • Now marks testing mock objects as a risky and useless tests
    • Mocks are only used to test other units
  • Coming in the future: The project is going to separate the project into the test framework and a test runner
  • PHP 7
    • built in support for support for code coverage
      • Utilizes phpdbg (with --qrr)
    • Tests run a shit ton faster. Tests run up 5x faster.

Drupal 8 single page apps

Chris Tankersley @dragonmantank

  • traditional web apps in php are heavy on processing on the server side
  • single page returns html, then makes additional requests for data that calls php, server returns JSON like data
  • caveats
    • SEO sucks
    • ad blocks may break site
    • your host might not support it
    • analytics become hard
  • create SPA if
    • you want a desktop like experience
      • e.g. gmail
  • things of SPA
    • Controller
    • Templating
    • Routing
  • Drupal 8 API
    • enable modules
      • HAL
      • HTTP Basic Auth
        • use https
      • RESTful Web Services
      • Serialization
    • set permissions for enabled modules
    • REST UI
      • Build routes through the UI
    • Set accept types
      • JSON, HAL JSON
      • HAL JSON gives additional context
  • Phil Sturgeons book "Build APIs you won't hate" is great

PHP7 and Beyond: The Future of PHP

Anthony Ferrara @ircmaxell

  • PHP is:
    • forgiving
    • Empowering
    • Not opinionated
  • PHP pillars
    • Platform
      • PHP is driven by contributors
      • 7.1 wishlist
        • Async support
        • lambdas
        • JIT?
        • full autoloading
        • annotations
      • The HHVM project is good for competition
        • It's driven PHP 7 and helping driving HHVM forward
    • Ecosystem
      • All the projects using PHP
      • PHP is here to support ecosytem
        • Can write OOP or not OOP
        • PHP supports both
      • PHP thrives with the ecosystem comes Together
        • PHP-FIG
        • gophp5
    • Community
      • individual communities aren't a sub set of PHP community, they over lap with PHP
        • e.g. Some people identify as PHP community, some as WordPress community, some as both. And that's all awesome
    • Toxicity Individuality
      • projecting insecurities on others
      • Assume someone has something positive to contribute even if they don't know they have anything to contribute
      • Be different and come together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment