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

PHP your perfect tool

PHP your perfect tool

Why you should choose PHP for your next project

Milan Popović

April 20, 2015
Tweet

More Decks by Milan Popović

Other Decks in Programming

Transcript

  1. YOUR PERFECT TOOL
    Presented by /
    Milan Popović @komita1981

    View Slide

  2. ME
    PHP developer
    7 years in PHP development
    Work for 12 Mnkys
    I like to learn and share knowledge
    Active member of PHP Srbija

    View Slide

  3. YOU?
    Who are you?
    What's your experience in programming?
    What do you think about PHP?

    View Slide

  4. “There are only two kinds of programming
    languages: those people always bitch
    about and those nobody uses.”
    Bjarne Stroustrup

    View Slide

  5. View Slide

  6. HISTORY OF PHP
    Created in 1994 by Rasmus Lerdorf - @rasmus
    Written in C
    Personal Home Page Tools
    ZEND - Andi Gutmans and Zeev Suraski
    PHP - Hypertext Preprocessor

    View Slide

  7. TIMELINE
    PHP 1 - 1995
    PHP 2 - 1996
    PHP 3 - 1998 - popularity gained
    PHP 4 - 2000 - wannabe object
    PHP 5 - 2004 - OO support
    PHP 5.3 - 2009 - Namespaces
    PHP 5.4 - 2012 - Traits, []
    PHP 5.5 - 2013 - OPcache, Finally
    PHP 5.6 - 2014 - Constant Scalar Expressions
    PHP 7 - October 2015

    View Slide

  8. May 2014 - PHP github repo
    April 2015 - PHP github repo

    View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. WHY YOU SHOULD CHOOSE PHP?

    View Slide

  17. HOSTING
    Shared
    VPS
    Dedicated servers
    Heroku
    Google App Engine
    Azure

    View Slide

  18. POPULARITY - TIOBE INDEX

    View Slide

  19. Popularity - usage of languages on web

    View Slide

  20. COMMUNITY
    More than 5 millions PHP developers worldwide
    Up to thousand PHP developers in Serbia

    View Slide

  21. ACTIVITY

    View Slide

  22. View Slide

  23. View Slide

  24. Simplicity - Highly learnable
    The easiest language to learn for non-technical people
    Fast and reliable
    Platform independent
    Bunch of good tools
    Bunch of extensions
    Good (and extensive) documentation
    Big players involved (FB...)
    Open source
    Lets you get things done

    View Slide

  25. PREJUDICE





    View Slide

  26. Tim Bray
    “All the PHP code I’ve seen in that
    experience has been messy,
    unmaintainable crap. Spaghetti SQL
    wrapped in spaghetti PHP wrapped in
    spaghetti HTML, replicated in slightly-
    varying form in dozens of places”

    View Slide

  27. namespace League\Flysystem;
    use LogicException;
    use InvalidArgumentException;
    class Filesystem implements FilesystemInterface
    {
    // variable declaration hidden in this example
    /**
    * Constructor
    *
    * @param AdapterInterface $adapter
    * @param mixed $config
    */
    public function __construct(AdapterInterface $adapter, $config = null)

    View Slide

  28. EDUCATION

    View Slide

  29. PHP THE RIGHT WAY

    View Slide

  30. LARACAST

    View Slide

  31. BOOKS
    http://php-books.com/

    View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. CONFERENCES

    View Slide

  36. PHP FIG
    PHP Framework Interop Group

    View Slide

  37. View Slide

  38. PSR
    Php Standard Recommendation
    PSR-0 - Autoloading standard
    PSR-1 - Basic coding standard
    PSR-2 - Coding style guide
    PSR-3 - Logger interface
    PSR-4 - Improved autoloading
    PSR-5 - PHPDoc
    PSR-6 - Cache interface
    PSR-7 - HTTP message implementation

    View Slide

  39. COMPOSER
    Dependency Manager for PHP
    Created by Jordi Boggiano and Nils Adermann
    Thank you guys!

    View Slide

  40. Fabien Potencier
    “PHP has a better dependency manager
    than any other languages”

    View Slide

  41. curl -sS https://getcomposer.org/installer | php
    Can be installed globally and locally

    View Slide

  42. The problem that Composer solves is this:
    You have a project that depends on a number of libraries
    Some of those libraries depend on other libraries
    You declare the things you depend on
    Composer finds out which versions of which packages
    need to be installed, and installs them (meaning it
    downloads them into your project)

    View Slide

  43. Declaring dependencies
    composer.json
    {
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
    "framework",
    "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
    "php": ">=5.3.3",
    "zendframework/zendframework": "2.2.*",
    "aws/aws-sdk-php-zf2": "1.2.1",
    "league/flysystem": "0.4.*@dev"
    }
    }

    View Slide

  44. View Slide

  45. SEMANTIC VERSIONING
    more info - http://semver.org/

    View Slide

  46. VERSION CONSTRAINTS

    View Slide

  47. EXACT MATCH
    1.0.0, dev-master

    View Slide

  48. WILDCARD RANGE
    1.0.*, 2.*

    View Slide

  49. HYPHEN RANGE
    1.0 - 2.0 === >=1.0.0 < 2.1
    1.0.0 - 2.1.0 === >=1.0.0 <= 2.1.0

    View Slide

  50. UNBOUNDED RANGE
    >= 1.0
    DO NOT USE THIS

    View Slide

  51. NEXT SIGNIFICANT RELEASE
    ~1.2 === >=1.2.0 <2.0.0
    ~1.2.3 === >=1.2.3 <1.3.0

    View Slide

  52. CARET / SEMVER OPERATOR
    ^1.2.3 === >=1.2.3 <2.0.0
    ^ 0.3 === >=0.3.0 <0.4.0
    Libraries should use ^ and you should too!

    View Slide

  53. THE LOCK FILE
    composer.lock
    Provide fast installs with low memory usage
    Reproducible installs
    Do you add it to .gitignore?
    Commit it and use it with composer install

    View Slide

  54. DO NOT DEPLOY IT

    View Slide

  55. AUTOLOADING
    You don’t have to maintain your own autoloader
    Ability to load your code automatically
    include "vendor/autoload.php";

    View Slide

  56. "autoload": {
    "psr-0" : {
    "Application": "src/"
    }
    }

    View Slide

  57. "autoload": {
    "psr-4" : {
    "Application\\": "src/"
    }
    }

    View Slide

  58. "autoload": {
    "classmap" : [
    "src/"
    ]
    }

    View Slide

  59. $baseDir . '/src/Application/Cont
    'Application\\Controller\\Defaults' => $baseDir . '/src/Application/Control
    'Application\\Controller\\Entry' => $baseDir . '/src/Application/Controller
    'Application\\Controller\\Logbook' => $baseDir . '/src/Application/Controll
    'Application\\Controller\\RequiresAuth' => $baseDir . '/src/Application/Con
    'Application\\Controller\\User' => $baseDir . '/src/Application/Controller/
    'Application\\Model\\LogEntry\\Defaults' => $baseDir . '/src/Application/Mo
    'Application\\Model\\LogEntry\\Gateway' => $baseDir . '/src/Application/Mod

    View Slide

  60. {
    "require": {
    "vendor/package": "1.3.2",
    "vendor/package2": "1.*",
    "vendor/package3": ">=2.0.3"
    }
    }

    View Slide

  61. PACKAGIST STATISTICS - MAY 2014
    29 908 packages registered
    110 247 versions available
    207 357 630 packages installed (since 2012-04-13)

    View Slide

  62. PACKAGIST STATISTICS - APRIL 2015
    56 164 packages registered
    246 789 versions available
    687 988 359 packages installed (since 2012-04-13)

    View Slide

  63. View Slide

  64. https://github.com/ziadoz/awesome-php

    View Slide

  65. View Slide

  66. View Slide

  67. BEFORE YOU CHOOSE PACKAGE
    Check if it is properly tested
    Check documentation (README.md)
    Check Stability
    dev -> alpha -> beta -> RC -> stable
    Check number of downloads
    Check when it was last authored
    Check the licence

    View Slide

  68. PHP FRAMEWORKS

    View Slide

  69. Zend Framework 2
    Symfony 2
    Laravel 4, 5
    Yii 2
    CakePHP 3
    Aura

    View Slide

  70. PhalconPhp
    Slim
    Silex
    Lumen

    View Slide

  71. View Slide

  72. TAKE CARE ABOUT THIS
    What do you want to build?
    Is good documentation available?
    Is it worth the investment?
    Community
    Comparing with other FW
    Check the licence
    Security

    View Slide

  73. 3 DONT'S
    Don't spend countless hours in search of the „best“
    framework. There is no such thing!
    Don't get religious with a language / framework /
    whatever!
    Don't decide based on stupid „hello world“ benchmarks.

    View Slide

  74. SYMFONY 2
    “If you have a PHP problem the Symfony
    community has already solved it”

    View Slide

  75. View Slide

  76. View Slide

  77. There is bundle for everything
    Integrates with Doctrine, Propel, PHPUnit ...
    Aims to speed up the creation and maintenance of web
    applications
    Aim at building enterprise-level applications, giving
    developers full control over the configuration

    View Slide

  78. View Slide

  79. LARAVEL
    The Swiss-Knife of Startup world
    The Most Popular FW of 2015
    FW with the best marketing

    View Slide

  80. Symfony components used by Laravel

    View Slide

  81. Database agnostic migrations and schema builder
    Great ORM - Eloquent
    Painless routing
    Blade Templating Engine
    Powerful queue library
    Validation
    Built with testing in mind

    View Slide

  82. LARAVEL ECOSYSTEM
    Forge
    Homestead
    Elixir
    Envoyer
    Laracast

    View Slide

  83. PHALCONPHP
    "The fastest framework"

    View Slide

  84. Implemented as a C extension
    Learning curve is pretty easy
    Support Micro and Macro application
    Loosely coupled to allow developers to use the whole
    framework or selected objects
    Neat and clean intuitive API with solid code written on
    powerful design patterns

    View Slide

  85. View Slide

  86. PHP IS NOT FOR
    Building command line apps
    Doing heavy calculation
    Calculate statistics
    You need all the performance you can get

    View Slide

  87. THANK YOU

    View Slide

  88. QUESTIONS?

    View Slide