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

Things you should know about PHP

Things you should know about PHP

An introduction to PHP, presented to the Swansea Software Development Community (SSDC) and PHP South West.

Oliver Davies

January 12, 2023
Tweet

More Decks by Oliver Davies

Other Decks in Technology

Transcript

  1. Things to know about PHP Oliver Davies (@opdavies) https://oliverdavies.uk/things-about-php

  2. @opdavies

  3. elePHPants! @opdavies

  4. What is PHP? PHP is a popular general-purpose scripting language

    that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world. http://php.net @opdavies
  5. Personal Home Page @opdavies

  6. PHP: Hypertext Preprocessor (recursive acronym) @opdavies

  7. @opdavies

  8. @opdavies

  9. @opdavies

  10. How do I get started? @opdavies

  11. php -v @opdavies

  12. PHP 8.1.0 (cli) (built: Nov 30 2021 07:15:23) (NTS) Copyright

    (c) The PHP Group Zend Engine v4.1.0, Copyright (c) Zend Technologies @opdavies
  13. vim index.php @opdavies

  14. Your first PHP file 1 <?php 2 3 // index.php

    @opdavies
  15. Your first PHP file 1 <?php 2 3 // index.php

    4 5 echo 'Hello World'; @opdavies
  16. php index.php @opdavies

  17. php -S localhost:8000 @opdavies

  18. /app # php -S localhost:8000 [Tue Mar 8 20:52:39 2022]

    PHP 8.1.0 Development Server (http://localhost:8000) started @opdavies
  19. @opdavies

  20. docker run --rm -v $PWD:/app -w /app php:8.1-cli-alpine php index.php

    @opdavies
  21. docker run --rm -v $PWD:/app -w /app php:7.4-cli-alpine php index.php

    @opdavies
  22. docker run --rm -v $PWD:/var/www/html -p 80:80 php:8.1-apache @opdavies

  23. 1 <?php 2 3 // index.php 4 5 function say()

    6 { 7 echo 'Hello!'; 8 } @opdavies
  24. 1 <?php 2 3 // index.php 4 5 function say($value)

    6 { 7 echo $value; 8 } @opdavies
  25. 1 <?php 2 3 // index.php 4 5 function say(string

    $value): void 6 { 7 echo $value; 8 } @opdavies
  26. 1 <?php 2 3 // index.php 4 5 function say(string

    $value): string 6 { 7 return $value; 8 } @opdavies
  27. 1 <?php 2 3 // src/Person.php 4 5 class Person

    6 { 7 public function say(string $value): void 8 { 9 echo $value; 10 } 11 } @opdavies
  28. 1 <?php 2 3 // Version 1. 4 say(); @opdavies

  29. 1 <?php 2 3 // Version 1. 4 say(); 5

    6 // Version 2. 7 say('something'); @opdavies
  30. 1 <?php 2 3 // Version 1. 4 say(); 5

    6 // Version 2. 7 say('something'); 8 9 // Version 3. 10 $person = new Person(); 11 $person->say('something'); @opdavies
  31. Levelling Up Content Management Systems @opdavies

  32. These lists are not exhaustive @opdavies

  33. @opdavies

  34. @opdavies

  35. @opdavies

  36. @opdavies

  37. @opdavies

  38. Levelling Up Frameworks @opdavies

  39. @opdavies

  40. @opdavies

  41. @opdavies

  42. But I only need a static site Static site generators

    @opdavies
  43. @opdavies

  44. @opdavies

  45. Code reuse and collaboration @opdavies

  46. @opdavies

  47. @opdavies

  48. @opdavies

  49. @opdavies

  50. composer require symfony/console @opdavies

  51. { "require": { "symfony/console": "^4.2" } } @opdavies

  52. 1 <?php 2 3 require 'vendor/autoload.php'; @opdavies

  53. 1 <?php 2 3 require 'vendor/autoload.php'; 4 5 $app =

    new \Symfony\Component\Console\Application(); 6 $app->run(); @opdavies
  54. 1 <?php 2 3 require 'vendor/autoload.php'; 4 5 use Symfony\Component\Console\Application;

    6 7 $app = new Application(); 8 $app->run(); @opdavies
  55. @opdavies

  56. @opdavies

  57. Tools @opdavies

  58. @opdavies

  59. @opdavies

  60. @opdavies

  61. @opdavies

  62. @opdavies

  63. 1 <?php 2 3 // PHPUnit. 4 5 use App\Email;

    6 7 final class EmailTest extends TestCase 8 { 9 public function testCanBeCreatedFromValidEmailAddress(): void 10 { 11 $this->assertInstanceOf( 12 Email::class, 13 Email::fromString('[email protected]') 14 ); 15 } 16 } @opdavies
  64. 1 <?php 2 3 // Pest. 4 5 use App\Email;

    6 7 it('can be created from a valid email address', function () { 8 expect(Email::fromString('[email protected]')) 9 ->toBeInstanceOf(Email::class); 10 }); @opdavies
  65. @opdavies

  66. Feature: ls In order to see the directory structure As

    a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ @opdavies
  67. @opdavies

  68. Learning @opdavies

  69. @opdavies

  70. @opdavies

  71. @opdavies

  72. @opdavies

  73. @opdavies

  74. @opdavies

  75. @opdavies

  76. The Community @opdavies

  77. @opdavies

  78. @opdavies

  79. @opdavies

  80. Things you should know about PHP • Very easy to

    get started • A large choice of tools and frameworks • A great worldwide community • Great learning resources • Gain experience by contributing to open source projects @opdavies
  81. Thanks! References: • https://www.oliverdavies.uk/things-about-php Me: • https://www.oliverdavies.uk @opdavies