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. ME PHP developer 7 years in PHP development Work for

    12 Mnkys I like to learn and share knowledge Active member of PHP Srbija
  2. “There are only two kinds of programming languages: those people

    always bitch about and those nobody uses.” Bjarne Stroustrup
  3. 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
  4. 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
  5. 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
  6. PREJUDICE <!--?php $db = connect_mysql('192.168.1.1', 'root' , 'secretPassword123' ); $item

    = get_mysql_data('SELECT * FROM my_table WHERE id= $_GET['id' ?--> <title><?php echo $item['title'];?></title> <div> <!--?php $users = get_mysql_data('SELECT * FROM users WHERE bla = '.$ite ?--> <!--?php foreach($users as $user){ ?-->
  7. 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”
  8. 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)
  9. 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
  10. 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)
  11. 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" } }
  12. HYPHEN RANGE 1.0 - 2.0 === >=1.0.0 < 2.1 1.0.0

    - 2.1.0 === >=1.0.0 <= 2.1.0
  13. 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!
  14. 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
  15. AUTOLOADING You don’t have to maintain your own autoloader Ability

    to load your code automatically include "vendor/autoload.php";
  16. <!--?php // autoload_classmap.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir

    = dirname($vendorDir); return array( 'Application\\Controller\\Dashboard' =--> $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
  17. PACKAGIST STATISTICS - MAY 2014 29 908 packages registered 110

    247 versions available 207 357 630 packages installed (since 2012-04-13)
  18. PACKAGIST STATISTICS - APRIL 2015 56 164 packages registered 246

    789 versions available 687 988 359 packages installed (since 2012-04-13)
  19. 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
  20. 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
  21. 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.
  22. SYMFONY 2 “If you have a PHP problem the Symfony

    community has already solved it”
  23. 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
  24. Database agnostic migrations and schema builder Great ORM - Eloquent

    Painless routing Blade Templating Engine Powerful queue library Validation Built with testing in mind
  25. 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
  26. PHP IS NOT FOR Building command line apps Doing heavy

    calculation Calculate statistics You need all the performance you can get