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

    View full-size slide

  2. elePHPants!
    @opdavies

    View full-size slide

  3. 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

    View full-size slide

  4. Personal Home Page
    @opdavies

    View full-size slide

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

    View full-size slide

  6. How do I get started?
    @opdavies

    View full-size slide

  7. php -v
    @opdavies

    View full-size slide

  8. 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

    View full-size slide

  9. vim index.php
    @opdavies

    View full-size slide

  10. Your first PHP file
    1 2
    3 // index.php
    @opdavies

    View full-size slide

  11. Your first PHP file
    1 2
    3 // index.php
    4
    5 echo 'Hello World';
    @opdavies

    View full-size slide

  12. php index.php
    @opdavies

    View full-size slide

  13. php -S localhost:8000
    @opdavies

    View full-size slide

  14. /app # php -S localhost:8000
    [Tue Mar 8 20:52:39 2022] PHP 8.1.0 Development Server
    (http://localhost:8000) started
    @opdavies

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. 1 2
    3 // index.php
    4
    5 function say($value)
    6 {
    7 echo $value;
    8 }
    @opdavies

    View full-size slide

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

    View full-size slide

  21. 1 2
    3 // index.php
    4
    5 function say(string $value): string
    6 {
    7 return $value;
    8 }
    @opdavies

    View full-size slide

  22. 1 2
    3 // src/Person.php
    4
    5 class Person
    6 {
    7 public function say(string $value): void
    8 {
    9 echo $value;
    10 }
    11 }
    @opdavies

    View full-size slide

  23. 1 2
    3 // Version 1.
    4 say();
    @opdavies

    View full-size slide

  24. 1 2
    3 // Version 1.
    4 say();
    5
    6 // Version 2.
    7 say('something');
    @opdavies

    View full-size slide

  25. 1 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

    View full-size slide

  26. Levelling Up
    Content Management Systems
    @opdavies

    View full-size slide

  27. These lists are not exhaustive
    @opdavies

    View full-size slide

  28. Levelling Up
    Frameworks
    @opdavies

    View full-size slide

  29. But I only need a static site
    Static site generators
    @opdavies

    View full-size slide

  30. Code reuse and collaboration
    @opdavies

    View full-size slide

  31. composer require
    symfony/console
    @opdavies

    View full-size slide

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

    View full-size slide

  33. 1 2
    3 require 'vendor/autoload.php';
    @opdavies

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. Tools
    @opdavies

    View full-size slide

  37. 1 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

    View full-size slide

  38. 1 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

    View full-size slide

  39. 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

    View full-size slide

  40. Learning
    @opdavies

    View full-size slide

  41. The Community
    @opdavies

    View full-size slide

  42. 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

    View full-size slide

  43. Thanks!
    References:
    • https://www.oliverdavies.uk/things-about-php
    Me:
    • https://www.oliverdavies.uk
    @opdavies

    View full-size slide