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. 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
  2. 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
  3. Your first PHP file 1 <?php 2 3 // index.php

    4 5 echo 'Hello World'; @opdavies
  4. /app # php -S localhost:8000 [Tue Mar 8 20:52:39 2022]

    PHP 8.1.0 Development Server (http://localhost:8000) started @opdavies
  5. 1 <?php 2 3 // index.php 4 5 function say()

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

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

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

    $value): string 6 { 7 return $value; 8 } @opdavies
  9. 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
  10. 1 <?php 2 3 // Version 1. 4 say(); 5

    6 // Version 2. 7 say('something'); @opdavies
  11. 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
  12. 1 <?php 2 3 require 'vendor/autoload.php'; 4 5 $app =

    new \Symfony\Component\Console\Application(); 6 $app->run(); @opdavies
  13. 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
  14. 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
  15. 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
  16. 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