From 9b92eb90ec5c3c90d3d6e3ebda47cecb8b796bce Mon Sep 17 00:00:00 2001 From: Barney Laurance Date: Tue, 25 Feb 2020 15:57:28 +0000 Subject: [PATCH 01/40] Empty test commit for gh-pages branch From 672b91fbfab0168f1db79fa86557c6a47b2b9285 Mon Sep 17 00:00:00 2001 From: Barney Laurance Date: Tue, 25 Feb 2020 15:59:55 +0000 Subject: [PATCH 02/40] Add test index.html for gh pages --- index.html | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..5c11777 --- /dev/null +++ b/index.html @@ -0,0 +1,5 @@ + + +test + + From ebe286cf94c050d115cf1ff1a7d35a47bb3a6f07 Mon Sep 17 00:00:00 2001 From: Barney Laurance Date: Tue, 25 Feb 2020 16:01:06 +0000 Subject: [PATCH 03/40] no jekyll --- .nojekyll | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .nojekyll diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 From c3f3fc4390b7b8bbfa126ace83581d3581a0e4cf Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 25 Feb 2020 20:04:26 +0000 Subject: [PATCH 04/40] Update GH Pages based on CircleCI Build 70 --- 01-introduction.html | 87 +++++++++++++++++++++++ 02-getting-php.html | 85 +++++++++++++++++++++++ 03-hello-world.html | 77 +++++++++++++++++++++ 04-http.html | 64 +++++++++++++++++ 05-variables.html | 131 +++++++++++++++++++++++++++++++++++ 06-functions.html | 87 +++++++++++++++++++++++ 07-classes-1.html | 153 +++++++++++++++++++++++++++++++++++++++++ 08-classes-2.html | 142 ++++++++++++++++++++++++++++++++++++++ 09-classes-3.html | 156 +++++++++++++++++++++++++++++++++++++++++ 10-testing.html | 160 +++++++++++++++++++++++++++++++++++++++++++ css/styles.css | 35 ++++++++++ index.html | 5 -- 12 files changed, 1177 insertions(+), 5 deletions(-) create mode 100644 01-introduction.html create mode 100644 02-getting-php.html create mode 100644 03-hello-world.html create mode 100644 04-http.html create mode 100644 05-variables.html create mode 100644 06-functions.html create mode 100644 07-classes-1.html create mode 100644 08-classes-2.html create mode 100644 09-classes-3.html create mode 100644 10-testing.html create mode 100644 css/styles.css delete mode 100644 index.html diff --git a/01-introduction.html b/01-introduction.html new file mode 100644 index 0000000..2dc0242 --- /dev/null +++ b/01-introduction.html @@ -0,0 +1,87 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Who is this for?

+

This is for anyone who wants to learn to program in PHP as a second language.

+

You should already know at least one programming language with curly braces, if conditions, variables, functions and +loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses +a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, +you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and +Typescript.

+

Why did I write it?

+

(This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

+

I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP +side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory +tutorial to recommend they can work through, but I didn't find anything satisfying.

+

The tutorial at php.net appears not to have been updated for several years, +and doesn't even introduce either the function or class keywords. On the other hand it does show PHP mixed with HTML, +which I plan to pretend doesn't exist. I think it's now probably worse than useless.

+

David Brumbaugh's +Learn a New Language: Migrating from JavaScript to PHP +is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what composer is, +and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to +require the reader to install at least PHP 7.2, and spend little if any time on older versions.

+

PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good +advice, but it's not really a tutorial to work through step by step. I think it could be overwhelming as an introduction +to PHP, and covers a lot more than I think most new PHP developers would want to know, including several paragraphs about +the MySQL Extension, which as it says "is incredibly old and has been superseded by two other extensions". I plan to +concentrate on the parts of PHP that I can recommend.

+

For PHP devs learning some Javascript, typescript, and/or React there seem to be great materials available online, +such as the React Tutorial, +HTML Dog's Javascript Tutorials, +TypeScript in 5 minutes and the (paid) Typescript course at +Execute Program. As far as I can tell there's nothing similar available free to help +JS devs learn some PHP.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/02-getting-php.html b/02-getting-php.html new file mode 100644 index 0000000..8c92916 --- /dev/null +++ b/02-getting-php.html @@ -0,0 +1,85 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Getting PHP

+

If you just want to run a PHP one-liner, or experiment with a tiny throwaway PHP script, the easiest way is probably +online at 3v4l, but to work through this tutorial you should have PHP installed on your computer.

+

Installation

+

First check if you already have PHP installed. Open your command-line prompt, and type php --v. If you have PHP, you +should see something like the following:

+
PHP 7.4.2 (cli) (built: Jan 23 2020 11:21:30) ( NTS )
+Copyright (c) The PHP Group
+Zend Engine v3.4.0, Copyright (c) Zend Technologies
+    with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
+

Check the first two parts of the version number, e.g. 7.4 above. This is the current version of PHP. Supported older +versions are 7.3 and 7.2. If you have an older version you will need to upgrade before using this tutorial.

+

Very few people download PHP directly from php.net. If you work with PHP developers you may want to check where +they install their PHP packages from and do the same. Installation methods vary with your operating system:

+

Linux

+

On Linux, use your package manager to install PHP, e.g. with the sudo apt install php command on Ubuntu, or Debian, and +sudo dnf -y install php-cli on Fedora. However these may not give you a recent enough version of PHP. You can get +more up to date packages for Ubuntu from Ondřej Surý for Ubuntu or +from Remi's RPM Repository for Red Hat, CentOs and Fedora.

+

Macintosh

+

Apple supplies PHP as part of OS X, but this is 7.1, and you need at least 7.2. The best way to get that is probably +through Homebrew. If you don't have it, first install the Homebrew package manager by following the instructions at +brew.sh, and then enter the command brew install php && brew link php.

+

Windows

+

I personally don't have a Windows machine, but I think the easiest way to set up PHP on Windows is as part of the +XAMPP package. Download and run the installer from Apache Friends. This +package bundles PHP along with the Apache web server, MariaDB database server, and the perl language. Xampp is also available +for Linux and Macintosh.

+

Run php -v again. Hopefully you will now have version 7.2 or later.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/03-hello-world.html b/03-hello-world.html new file mode 100644 index 0000000..44b88a2 --- /dev/null +++ b/03-hello-world.html @@ -0,0 +1,77 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Hello, world.

+

At this point we're ready to start writing in PHP. Make a new folder for your PHP scripts.

+

If you have a favourite text editor or integrated development environment, such as vim, atom, or vs-code you may want to +stick with that, but the best tool for editing PHP code is almost certainly JetBrains' +PhpStorm. PhpStorm is free for 30 days, but will demand money after that.

+

Make a new file called hello.php, and type in the following:

+
<?php declare(strict_types=1);
+
+echo "Hello, world.\n";
+

Save the file, and go to your command line. Navigate to your PHP scripts folder, and run your first PHP program by +typing php hello.php. You should see:

+
$ php hello.php
+Hello, world
+$
+

Every PHP file should start with <?php declare(strict_types=1); . This tells the PHP interpreter that you're writing +PHP, and strict_types tells PHP not to try to guess what you mean so much. Historically PHP has tended to be very +loose, and prefer to make the best guess of what's required if it isn't clear instead of giving up. That's probably good +for writing a website one page at a time, but for applications we need the computer to stop and tell us what's wrong +if we make a mistake, not plough ahead and give us a wrong result.

+

echo simply outputs strings of text. We could use print, which is quicker to say, but we prefer echo, which is +20% shorter to write.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/04-http.html b/04-http.html new file mode 100644 index 0000000..f981295 --- /dev/null +++ b/04-http.html @@ -0,0 +1,64 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

HTTP

+

PHP is of course mostly used in web servers, so you might be wondering why we started with a command line script.

+

In fact you can access the same script through your web browser. PHP comes with a built-in web server for development +and testing uses. To start it, run:

+
php -S localhost:8080
+

Point your browser at http://localhost:8080/hello.php, and you should see +"Hello, world.".

+

Go back to your command line and press ctrl-c to shut down the server.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/05-variables.html b/05-variables.html new file mode 100644 index 0000000..ee8f6ed --- /dev/null +++ b/05-variables.html @@ -0,0 +1,131 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Variables, arrays and loops

+

Variables in PHP always have a dollar sign $ at the start of their names, and you declare a variable by assigning a +value to it. PHP interpolates double-quoted strings with variables. Edit hello.php to use a variable:

+
<?php declare(strict_types=1);
+
+$planet = "earth";
+
+echo "Hello, $planet.\n";
+
+

You can probably guess what this will do when you run it on your command line or serve it to your browser.

+

Arrays and loops

+

PHP has a very versatile built-in type called array. You're unlikely to find much PHP code that doesn't use arrays +extensively, but they are easy to overuse at the cost of other more expressive types. Despite the name, a PHP array +isn't really an array as you may know it from other languages. A PHP array is an ordered iterable dictionary, with keys +and values. The keys may be strings or integers, and by default will be sequential integers starting at zero. The +values can be anything that could go in a variable, including more arrays.

+

An array is not an object in PHP — we will get on to objects later.

+

Let's edit our script to declare an array and iterate through it:

+
<?php declare(strict_types=1);
+
+$planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'];
+
+foreach ($planets as $planet) {
+    echo "Hello, $planet.\n";
+}
+
+$dwarfPlanet = 'Pluto';
+echo "Hello, $dwarfPlanet.\n";
+

If you run this you should see:

+
$ php hello.php 
+Hello, Mercury.
+Hello, Venus.
+Hello, Earth.
+Hello, Mars.
+Hello, Jupiter.
+Hello, Saturn.
+Hello, Uranus.
+Hello, Neptune.
+Hello, Pluto.
+
+

foreach assigns each value from the array to the $planet variable in turn. We edit the script to ask it to give us +the numeric keys that were implicitly set on line 3:

+
<?php declare(strict_types=1);
+
+$planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'];
+
+foreach ($planets as $number => $planet) {
+    echo "Hello, $planet, you are planet number $number.\n";
+}
+
+$dwarfPlanet = 'Pluto';
+echo "Hello, $dwarfPlanet.\n";
+

The PHP manual lists 81 functions for manipulating arrays. For now let's +just try one: natsort. Add new line before foreach:

+
natsort($planets);
+

Re-run the script - the planets are now listed in alphabetical order. But notice that the array keys have not changed - +Mercury is still planet number 0, it's just that 0 now happens to come after 3. PHP array keys can come in any +order.

+

Associative arrays

+

We can also assign array keys explicitly. When we're interested in the keys of an array we call it an +associative array. For example:

+
<?php declare(strict_types=1);
+
+$planetPopulations = [
+    'Mercury' => 0,
+    'Venus' => 0,
+    'Earth' => 7.7 * 10**9,
+    'Mars' => 0,
+    'Jupiter' => 0,
+    'Saturn' => 0,
+    'Uranus' => 0,
+    'Neptune' => 0,
+];
+
+echo "The population of Earth is {$planetPopulations['Earth']}.\n";
+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/06-functions.html b/06-functions.html new file mode 100644 index 0000000..16cfa04 --- /dev/null +++ b/06-functions.html @@ -0,0 +1,87 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Functions

+

PHP comes with hundreds of built in functions, to sort arrays, find the length of strings, match regexes, or even +get the timestamp corresponding to midnight on Easter of a given year, +you will inevitably want to define your own functions. Function definitions look like this:

+
function getGreeting(string $planetName): string
+{
+    return "Hello, $planetName.\n";
+}
+

Notice the type declarations, string and : string. Strictly speaking these are optional, but you should add +them whenever you can. Like Typescript, PHP is a gradually typed language. However unlike Typescript, which does +type checking in the compiler, PHP applies type checking only when the relevant part of your program runs. Let's see +an example:

+
<?php declare(strict_types=1);
+
+function getGreeting(string $planetName): string
+{
+    return "Hello, $planetName.\n";
+}
+
+echo getGreeting('Magrathea');
+echo getGreeting(42);
+

Running this, you should see something like:

+
Hello, Magrathea.
+PHP Fatal error:  Uncaught TypeError: Argument 1 passed to getGreeting() must be of the type string, int given, called in functions.php on line 9 and defined in functions.php:3
+Stack trace:
+#0 functions.php(9): getGreeting()
+#1 {main}
+  thrown in functions.php on line 3
+

The first part of the program ran fine, but attempting to pass an integer to a function that we've declared with a +string parameter was a fatal error and caused a crash. If we'd tried to return anything other than a string from inside +the function that would also be a fatal error.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/07-classes-1.html b/07-classes-1.html new file mode 100644 index 0000000..f335c96 --- /dev/null +++ b/07-classes-1.html @@ -0,0 +1,153 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Classes and Objects

+

PHP supports class-based object oriented programming, heavily influenced by Java and similar languages. This is +different to the prototype based OO in JavaScript.

+

In the sort of PHP code I write almost 100% of the code is in a project is in classes - some classes are used to make +objects, and others may just be convenient wrappers around groups of functions.

+

In PHP every object is an instance of a class, so you have to have a class before you can have an object. Let's write +a class to let us make Planet objects. How to write classes changed a bit in PHP 7.4. Enter the +following in a file called Planet.php:

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+final class Planet
+{
+    private string $name;
+
+    private float $populationSize;
+
+    public function __construct(string $name, float $populationSize) 
+    {
+        $this->name = $name;
+        $this->populationSize = $populationSize;
+    }
+
+   public function getName(): string
+   {
+       return $this->name;
+   }
+
+   public function getPopulationSize(): float
+   {
+       return $this->populationSize;
+   }
+}
+

Older PHP Versions

+

name and populationSize are the properties of the class, and they have string and float types respectively. +Before 7.4 PHP didn't allow us to specify types for properties. We still want to know what types of values we intend to +put in the properties, so we use a DocBlock instead. If you don't have 7.4 yet, change the property declarations +to:

+
    /**
+     * @var string
+     */
+    private $name;
+
+    /**
+     * @var float
+     */
+    private float $populationSize;
+

These DocBlocks are ignored by the PHP engine, but they are very useful for us, and many tools and IDEs will read them. +The code inside the docblock is written in the PHPDoc language.

+

Running the code

+

Run php Planet.php. You should see no output - a class by itself doesn't do anything. We will write code to use this +class on the next page.

+

What's in the class

+

Let's read through the class from top to bottom.

+
    +
  • +

    The entire file is in a namespace. This is useful to help distinguish our code from other people's code, and +to distinguish between submodules when our program gets bigger. We will keep all our code in this namespace. The +namespace is effectively a prefix, so the full name of the class is \PhpAsASecondLanguage\Planet.

    +
  • +
  • +

    Planet is a final class. This prevents any other classes being written as subclasses of Planet. Subclassing is +beyond the scope of this tutorial, but for now we can say that it adds significant complexity, and if we don't need it +we should probably avoid it. It's therefore a good practice to make classes final by default - we can always delete the +word final if we ever find we do need to make a subclasses of Planet.

    +
  • +
  • +

    Planet has name and populationSize properties. When we create Planet objects every object will have its own copy +of these properties. private is the properties visibility - that means that the properties can only be directly read +or written by code within the Planet class. In the PHP 7.4 code they are typed properties, which that PHP will +do a type check at run time whenever we assign values to the properties, and it will only allow us to assign strings of +text and and floating point numbers - attempting to assign anything else would a fatal error.

    +

    We would also get a fatal error if we tried to read these typed properties before they are initialised.

    +
  • +
  • +

    Next we have three functions, also known as methods. These all have public visibility, which means we can call them from anywhere.

    +

    Functions whose names start with __ are considered Magic Methods in PHP - they have special meanings given by the +language. __construct is the Constructor, and will be automatically called whenever we create a Planet object with +the new keyword.

    +

    Finally we have our two getter functions. Since the properties are private, these public functions are needed to allow +code outside the class to read the properties. By keeping the properties private and creating getters but not setters +we can create an immutable object. It's verbose, but it's a lot easier to understand what's happening in a big project +with a class like this than it would be if the properties were public and code from lots of other places could be +writing to them.

    +

    These functions will be run with a given object instance of the class. The $this variable will refer to that +object. We use the arrow -> operator to access the properties and methods of any object.

    +

    Having getters also means that if we later want to change the class - perhaps to replace the +$populationSize property with an array that holds details of every person on the planet - we can edit the code inside +the getter function and make it return the size of the array. Code that uses this class wouldn't have to be +affected by the change. Changes tend to ripple through a codebase, and one of the most important things to do when +choosing how to write code is anticipating types of future changes, and putting barriers in place to limit the spread of +those changes.

    +
  • +
+

If you know JavaScript, you can think of a class with public and private parts as serving a similar purpose to a +JavaScript module that exports some but not all of its symbols.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/08-classes-2.html b/08-classes-2.html new file mode 100644 index 0000000..95b9d99 --- /dev/null +++ b/08-classes-2.html @@ -0,0 +1,142 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Classes Part 2

+

On the last page we wrote Planet class, and saved it in a file called Planet.php. Now we want to put that class +to work.

+

PHP works by executing whatever script we give it from beginning to end. It won't run anything inside a class unless +we that script tells it to, so every PHP program needs at least one line that isn't part of any class as an entry-point. +There is no equivalent to the main function of languages like C and Java.

+

By convention, and to follow the PSR-1 coding standard, we always put the entry point in a separate file to the +class declaration.

+

Let's write a simple script to create a planet and print out its details. Since at the moment Planet is just a data +holder the script won't be too exiting.

+

Write the following in a file called start.php

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+$planet = new Planet('Neptune', 0);
+
+echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";
+

The new keyword creates objects instances from classes, and automatically runs any constructor with the arguments we pass.

+

We can try running this now but it won't work just yet, because we need to link it up with Planet.php. When you type +php start.php you should see PHP Fatal error: Uncaught Error: Class 'Planet' not found.

+

Linking files together

+

There are two main ways to link files together. The old way is require_once, and the new ways is composer. We'll +start with require_once, but for all but the simplest of scripts we will want to use composer.

+

Require_once

+

Edit start.php to make it look like this:

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+require_once __DIR__ . '/Planet.php';
+
+$planet = new Planet('Neptune', 0);
+
+echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";
+

Run the script again, and you should now see Planet Neptune has a population of 0.. The require_once statement +tells PHP to process the contents of the given file as if it had been pasted in to the current script, ignoring +the <?php opening tag and the declare. The once part means that if we require the same file more than once PHP will +skip it on the second and subsequent times. That's what want for a class - once the class is loaded there's no need to +load it again, even if multiple parts of our program have to declare that they need that class.

+

__DIR__ is a PHP magic constant that refers to the directory of whatever file its used in. The dot . is PHP's string +concatenation operator.

+

But adding a require_once statement every time we need to use a class can quickly become tedious. It's what we all +mostly did until around 2015, when the Composer dependency management tool became popular, even prompting a rare +mention for PHP in the ThoughtWorks Technology Radar.

+

Composer

+

Composer is primarily a tool to help you add third party libraries and frameworks to your PHP projects, but since it +includes code to help us load the classes those libraries declare it makes sense to also use it to help us load our own +classes.

+

First check if you have composer installed - run composer about. On some systems it may be called composer.phar +instead of composer. If you have it, you should see "Composer - Dependency Manager for PHP". If not, +download and install composer from getcomposer.org, then come back to this page. I +suggest installing it to somewhere on your executable PATH, and naming it composer rather than composer.phar.

+

Let's adjust our script to use composer instead of require_once. First delete the require_once statement, to get back +to the class not found error we had before.

+

Create a subdirectory src and move Planet.php inside src. It's generally a good idea to have this to keep the bulk +of our source code separate from everything else in our project, e.g. the entry point file, any docs we might want to write, +tool config etc.

+

Composer works on a project-by-project basis. To set it up for your a project, you need to create a composer.json file. +To start with, just put an empty json object in this file:

+
{
+}
+

You can now run composer install. Composer should create a vendor subdirectory. Everything you install to you project +through composer will be in that directory. You would normally want to exclude vendor from source control.

+

Now we need to tell composer how to load your classes. The PSR-4 scheme is a standard way of translating between PHP +class names and file paths. Edit composer.json to look like the following:

+
{
+    "autoload": {
+        "psr-4": {
+            "PhpAsASecondLanguage\\": "src/"
+        }
+    }
+}
+

Re-run composer install, and then edit start.php to require Composer's autoloader:

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+require_once __DIR__. '/vendor/autoload.php';
+
+$planet = new Planet('Neptune', 0);
+echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";
+
+

As long as we keep our file names matching our class names, Composer will automatically load any class we need, and +only when we need it.

+

If you run php start.php you should once again learn the population of Neptune.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/09-classes-3.html b/09-classes-3.html new file mode 100644 index 0000000..2bfc17b --- /dev/null +++ b/09-classes-3.html @@ -0,0 +1,156 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Classes Part 3

+

Static methods

+

Not all the methods on a class have to run in the context of an object. Methods that work without a $this object +instance are called static methods. Let's add a static method to the Planet class in src/Planet.php:

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+final class Planet
+{
+    private string $name;
+
+    private float $populationSize;
+
+    public function __construct(string $name, float $populationSize) 
+    {
+        $this->name = $name;
+        $this->populationSize = $populationSize;
+    }
+
+   public function getName(): string
+   {
+       return $this->name;
+   }
+
+   public function getPopulationSize(): float
+   {
+       return $this->populationSize;
+   }
+
+   public static function earth(): self
+   {
+       return new self('Earth', 7.7 * 10**9);
+   }
+}
+ +

The self keyword refers to whatever class it's written in. It's more convenient to write self than to repeat +Planet many times.

+

And let's edit start.php:

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+require_once __DIR__. '/vendor/autoload.php';
+
+$planet = Planet::Earth();
+echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";
+

The double colon is officially called the Scope Resolution Operator. It access properties and methods of classes +without going through an object. In this case our method returns an instance of the class, but it could +do anything.

+

Object Identity

+

A PHP variable can't actually hold an object - instead it holds an object identifier, also known as a reference.

+

To objects created the same way, with the same properties will have distinct identities. But if one object is created +and then its assigned to two variables, they will both refer hold identifiers for the same object. This becomes +important when we make our objects mutable. This extra complexity is a good reason to prefer immutable objects, but +we will need mutability at times.

+

Let's add a function to change the world - edit src/Planet.php again, adding the following function inside the class:

+
   public function receiveImmigrant(): void
+   {
+       $this->populationSize++;
+   }
+

void is the return type for functions that don't actually return any information.

+

Let's write a script that illustrates identities. Enter the following in 'identities.php'

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+require_once __DIR__. '/vendor/autoload.php';
+
+$mercury = new Planet('Mercury', 0);
+$secondMercury = new Planet('Mercury', 0);
+$theSameMercury = $mercury;
+
+echo "Mercury is equal to second Mercury:\n";
+var_dump($mercury == $secondMercury);
+echo \PHP_EOL;
+
+echo "But Mercury is not **identical** to second Mercury:\n";
+var_dump($mercury === $secondMercury);
+echo \PHP_EOL;
+
+echo "Mercury is equal **and** identical to the same Mercury:\n";
+var_dump($mercury == $theSameMercury);
+var_dump($mercury === $theSameMercury);
+echo \PHP_EOL;
+
+$mercury->receiveImmigrant();
+
+echo "Population of Mercury: {$mercury->getPopulationSize()}.\n";
+echo "Population of second Mercury: {$secondMercury->getPopulationSize()}.\n";
+echo "Population of the same Mercury: {$theSameMercury->getPopulationSize()}.\n";
+

We see that $mercury and $theSameMercury are just two names for the same object, while $secondMercury is an +entirely separate object with its own properties, lifecycle, hopes and dreams.

+

If we use or write a function that accepts an object as a parameter, or returns an object, it's important to be aware +that PHP doesn't make a copy of the object - it just copies the identifier. This means that code within and without +the function can access and potentially change the same object. It's an important part of how communication happens +between the parts of a PHP program, but it can easily get confusing if not managed carefully.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/10-testing.html b/10-testing.html new file mode 100644 index 0000000..b5e449a --- /dev/null +++ b/10-testing.html @@ -0,0 +1,160 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Testing

+

If we want to work on even a moderately complex program over time, we need automated testing - manually testing +everything every time we make a change would quickly become unsustainable.

+

Installing PHPUnit

+

The leading test framework for PHP is Sebastian Bergmann's PHPUnit.

+

Since we already have composer set up for our project, we can use that to install PHPUnit in the vendor directory. Run:

+
composer require --dev phpunit/phpunit
+

Composer also automatically downloads and installs all the libraries that PHPUnit depends on, and the dependencies of +its dependencies, etc.

+

We use the --dev option because PHPUnit is a tool for developers, and not a library that our program would rely on +in production. If we wanted to prepare a copy of our program to install on a server, we would use the --no-dev option +of composer install to leave out PHPUnit.

+

When we ran the require command composer.json edited our composer.json file to record our updated requirements. +composer.json should now look like:

+
{
+    "autoload": {
+        "psr-4": {
+            "PhpAsASecondLanguage\\": "src/"
+        }
+    },
+    "require-dev": {
+        "phpunit/phpunit": "^9.0"
+    }
+}
+

The last major release of PHPUnit was 9.0, so composer has assumed we will always want whatever the latest PHPUnit +release in the 9 series is. The 10 series is not expected to be compatible with code written for PHPUnit 9, so composer +won't install that unless we edit composer json. Composer works best with dependencies that use semantic versioning, +aka semver.

+

Composer has also created a new file for us, composer.lock. This has metadata about the exact versions of the packages +installed. At the time of writing it shows me that PHPUnit is at version 9.0.1, and I can see the details of 29 other +packages that have been installed because PHPUnit depends on them directly or indirectly. The composer show command +will output the list of installed packages in a much more consice format.

+

Writing a test

+

Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

+
<?php declare(strict_types=1);
+
+namespace PhpAsASecondLanguage;
+
+use PHPUnit\Framework\TestCase;
+
+final class PlanetTest extends TestCase
+{
+    private Planet $SUT; // SUT = Subject Under Test
+
+    public function setUp(): void
+    {
+        $this->SUT = new Planet('planet name', 0);
+    }
+
+    public function test_it_can_accept_immigrant(): void
+    {
+        $this->assertSame(0.0, $this->SUT->getPopulationSize());
+        $this->SUT->receiveImmigrant();
+        $this->assertSame(1.0, $this->SUT->getPopulationSize());
+    }
+}
+

The new keyword here is extends. This means that our class is an extension, or subclass of PHPUnit's TestCase class, +which is how PHPUnit is designed to be used. If TestCase has been marked final we wouldn't be able to extend it.

+

If you're not on PHP 7.4, remember to remove the Planet property type for the SUT, and replace it with a docbloc as we +did for the properties of Planet itself.

+

It's prudent to see a test fail at least once before believing what it says when it passes. To make it fail, comment out +$this->populationSize++; in src/Planet.php:

+

// $this->populationSize++;

+

Now run the PHPUnit command:

+
vendor/bin/phpunit test
+

This will search for any filenames ending in Test.php in the test directory. In each test case any public function +whose name starts with test is considered a test. For every test PHPUnit creates an instance of the class, calls the +setup function, then calls the test function, records the results, and then throws away the object. So if we had two test +it would run the set up function twice. If an object is referenced only by garbage it is garbage, so when the test case +object is thrown away the Planet is thrown away too, and any mutations to the planet will not affect the next test.

+

The output from PHPUnit should look like:

+
PHPUnit 9.0.1 by Sebastian Bergmann and contributors.
+
+F                                                                   1 / 1 (100%)
+
+Time: 36 ms, Memory: 4.00 MB
+
+There was 1 failure:
+
+1) PhpAsASecondLanguage\PlanetTest::test_it_can_accept_immigrant
+Failed asserting that 0.0 is identical to 1.0.
+
+/tmp/composerPlayground/test/PlanetTest.php:20
+
+FAILURES!
+Tests: 1, Assertions: 2, Failures: 1.
+

Fix the Planet class putting the increment back in, and re-run the PHPUnit command. We should now see some happier +output:

+
PHPUnit 9.0.1 by Sebastian Bergmann and contributors.
+
+.                                                                   1 / 1 (100%)
+
+Time: 35 ms, Memory: 4.00 MB
+
+OK (1 test, 2 assertions)
+

Writing tests is a huge topic, which we can't cover in detail here. PHPUnit has excellent +official documentation. You might choose to do +Test Driven Development (TDD) / Behaviour Driven Development (BDD) and write your tests before writing the +production code that they cover.

+

Some other major test frameworks for PHP are PHPSpec and +Behat, which are both designed around the BDD approach, which +uses the language of executable specifications rather than tests. The major difference is that in PHPSpec, as with +PHPUnit, you code in PHP. In Behat you code in a separate language called gherkin, designed to be readable by project +stakeholders who haven't been trained in programming.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..2642b6b --- /dev/null +++ b/css/styles.css @@ -0,0 +1,35 @@ +#pages ul { + display:flex; + list-style:none; +} + +#pages ul li { + margin: 1em; +} + +body > div { + max-width: 1000px; + margin: auto; +} + +#byline { + text-align: right; +} + +#draft { + position: absolute; + top: 1.5em; + transform-origin: center; + transform: rotate(45deg); + font-size: 15em; + pointer-events: none; + font-weight: bolder; + color: rgba(0,0,0,0.07); +} + +#footer { + margin-top: 1em; + padding: 1em; + border: 2px solid #b0b0b0; + background-color: #dcdcdc; +} \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 5c11777..0000000 --- a/index.html +++ /dev/null @@ -1,5 +0,0 @@ - - -test - - From 78f3d7816a39ad1d8b039113848e003e328b3811 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 25 Feb 2020 20:16:36 +0000 Subject: [PATCH 05/40] Update GH Pages based on CircleCI Build 73 --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- index.html | 87 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 index.html diff --git a/01-introduction.html b/01-introduction.html index 2dc0242..1813ca0 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -78,7 +78,7 @@

Why did I write it?

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/02-getting-php.html b/02-getting-php.html index 8c92916..0170b74 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -76,7 +76,7 @@

Windows

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/03-hello-world.html b/03-hello-world.html index 44b88a2..61f8c2d 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -68,7 +68,7 @@

Hello, world.

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/04-http.html b/04-http.html index f981295..55bd859 100644 --- a/04-http.html +++ b/04-http.html @@ -55,7 +55,7 @@

HTTP

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/05-variables.html b/05-variables.html index ee8f6ed..dac2bfb 100644 --- a/05-variables.html +++ b/05-variables.html @@ -122,7 +122,7 @@

Associative arrays

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/06-functions.html b/06-functions.html index 16cfa04..d162560 100644 --- a/06-functions.html +++ b/06-functions.html @@ -78,7 +78,7 @@

Functions

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/07-classes-1.html b/07-classes-1.html index f335c96..a5bda5e 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -144,7 +144,7 @@

What's in the class

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/08-classes-2.html b/08-classes-2.html index 95b9d99..283f4ea 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -133,7 +133,7 @@

Composer

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/09-classes-3.html b/09-classes-3.html index 2bfc17b..34e9bea 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -147,7 +147,7 @@

Object Identity

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/10-testing.html b/10-testing.html index b5e449a..4bca1c8 100644 --- a/10-testing.html +++ b/10-testing.html @@ -151,7 +151,7 @@

Writing a test

-

Multiple versions of this site are currently online as CircleCI artifacts. This version generated Tue, 25 Feb 2020 20:04.

+

Site built Tue, 25 Feb 2020 20:16.

diff --git a/index.html b/index.html new file mode 100644 index 0000000..1813ca0 --- /dev/null +++ b/index.html @@ -0,0 +1,87 @@ + + + + + + + PHP as a Second Language + + + + + + + + +
+
DRAFT
+

PSL - PHP as a Second Language

+ +
+

Who is this for?

+

This is for anyone who wants to learn to program in PHP as a second language.

+

You should already know at least one programming language with curly braces, if conditions, variables, functions and +loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses +a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, +you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and +Typescript.

+

Why did I write it?

+

(This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

+

I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP +side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory +tutorial to recommend they can work through, but I didn't find anything satisfying.

+

The tutorial at php.net appears not to have been updated for several years, +and doesn't even introduce either the function or class keywords. On the other hand it does show PHP mixed with HTML, +which I plan to pretend doesn't exist. I think it's now probably worse than useless.

+

David Brumbaugh's +Learn a New Language: Migrating from JavaScript to PHP +is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what composer is, +and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to +require the reader to install at least PHP 7.2, and spend little if any time on older versions.

+

PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good +advice, but it's not really a tutorial to work through step by step. I think it could be overwhelming as an introduction +to PHP, and covers a lot more than I think most new PHP developers would want to know, including several paragraphs about +the MySQL Extension, which as it says "is incredibly old and has been superseded by two other extensions". I plan to +concentrate on the parts of PHP that I can recommend.

+

For PHP devs learning some Javascript, typescript, and/or React there seem to be great materials available online, +such as the React Tutorial, +HTML Dog's Javascript Tutorials, +TypeScript in 5 minutes and the (paid) Typescript course at +Execute Program. As far as I can tell there's nothing similar available free to help +JS devs learn some PHP.

+
+ +
+ Copyright Barney Laurance 2020 +
+ + + +
+ + \ No newline at end of file From 0cba002b03c2978780ff75659b7ecdd235438c9a Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 25 Feb 2020 20:25:35 +0000 Subject: [PATCH 06/40] Update GH Pages based on CircleCI Build 76 --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- index.html | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 1813ca0..b70aa76 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -78,7 +78,7 @@

    Why did I write it?

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/02-getting-php.html b/02-getting-php.html index 0170b74..3bf8dd1 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -76,7 +76,7 @@

    Windows

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/03-hello-world.html b/03-hello-world.html index 61f8c2d..516c595 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -68,7 +68,7 @@

    Hello, world.

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/04-http.html b/04-http.html index 55bd859..dd88e7d 100644 --- a/04-http.html +++ b/04-http.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -55,7 +55,7 @@

    HTTP

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/05-variables.html b/05-variables.html index dac2bfb..736f428 100644 --- a/05-variables.html +++ b/05-variables.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -122,7 +122,7 @@

    Associative arrays

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/06-functions.html b/06-functions.html index d162560..f9853c3 100644 --- a/06-functions.html +++ b/06-functions.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -78,7 +78,7 @@

    Functions

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/07-classes-1.html b/07-classes-1.html index a5bda5e..cd3f17b 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -144,7 +144,7 @@

    What's in the class

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/08-classes-2.html b/08-classes-2.html index 283f4ea..fe088b1 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -133,7 +133,7 @@

    Composer

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/09-classes-3.html b/09-classes-3.html index 34e9bea..38c4941 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -147,7 +147,7 @@

    Object Identity

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/10-testing.html b/10-testing.html index 4bca1c8..3fe1068 100644 --- a/10-testing.html +++ b/10-testing.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -151,7 +151,7 @@

    Writing a test

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

diff --git a/index.html b/index.html index 1813ca0..b70aa76 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@
DRAFT
-

PSL - PHP as a Second Language

+

PHP as a Second Language

  • 01-introduction
  • @@ -78,7 +78,7 @@

    Why did I write it?

    -

    Site built Tue, 25 Feb 2020 20:16.

    +

    Site built Tue, 25 Feb 2020 20:25.

From f8f63acdc46c7b9938c15bba84ad524a52dceebc Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 25 Feb 2020 20:37:17 +0000 Subject: [PATCH 07/40] Update GH Pages based on CircleCI Build 79 --- 01-introduction.html | 18 +++++++++++++++++- 02-getting-php.html | 18 +++++++++++++++++- 03-hello-world.html | 18 +++++++++++++++++- 04-http.html | 18 +++++++++++++++++- 05-variables.html | 18 +++++++++++++++++- 06-functions.html | 18 +++++++++++++++++- 07-classes-1.html | 18 +++++++++++++++++- 08-classes-2.html | 18 +++++++++++++++++- 09-classes-3.html | 18 +++++++++++++++++- 10-testing.html | 18 +++++++++++++++++- index.html | 18 +++++++++++++++++- 11 files changed, 187 insertions(+), 11 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index b70aa76..111f1e4 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -78,7 +94,7 @@

Why did I write it?

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/02-getting-php.html b/02-getting-php.html index 3bf8dd1..49c4793 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -76,7 +92,7 @@

Windows

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/03-hello-world.html b/03-hello-world.html index 516c595..cf9767b 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -68,7 +84,7 @@

Hello, world.

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/04-http.html b/04-http.html index dd88e7d..0743570 100644 --- a/04-http.html +++ b/04-http.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -55,7 +71,7 @@

HTTP

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/05-variables.html b/05-variables.html index 736f428..1c3f704 100644 --- a/05-variables.html +++ b/05-variables.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -122,7 +138,7 @@

Associative arrays

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/06-functions.html b/06-functions.html index f9853c3..b343072 100644 --- a/06-functions.html +++ b/06-functions.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -78,7 +94,7 @@

Functions

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/07-classes-1.html b/07-classes-1.html index cd3f17b..edbc3c3 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -144,7 +160,7 @@

What's in the class

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/08-classes-2.html b/08-classes-2.html index fe088b1..b62ef70 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -133,7 +149,7 @@

Composer

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/09-classes-3.html b/09-classes-3.html index 38c4941..0664e8e 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -147,7 +163,7 @@

Object Identity

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/10-testing.html b/10-testing.html index 3fe1068..a5e524f 100644 --- a/10-testing.html +++ b/10-testing.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -151,7 +167,7 @@

Writing a test

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

diff --git a/index.html b/index.html index b70aa76..111f1e4 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,22 @@ href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"> + + + + @@ -78,7 +94,7 @@

Why did I write it?

-

Site built Tue, 25 Feb 2020 20:25.

+

Site built Tue, 25 Feb 2020 20:37.

From 913780d1ebd7694f97354d33c8eb701de6468b20 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 25 Feb 2020 20:45:39 +0000 Subject: [PATCH 08/40] Update GH Pages based on CircleCI Build 82 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- index.html | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 111f1e4..6f3be1a 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -94,7 +94,7 @@

Why did I write it?

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/02-getting-php.html b/02-getting-php.html index 49c4793..0ecfbf4 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -92,7 +92,7 @@

Windows

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/03-hello-world.html b/03-hello-world.html index cf9767b..55c47f9 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -84,7 +84,7 @@

Hello, world.

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/04-http.html b/04-http.html index 0743570..e71dea7 100644 --- a/04-http.html +++ b/04-http.html @@ -71,7 +71,7 @@

HTTP

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/05-variables.html b/05-variables.html index 1c3f704..c10cdbb 100644 --- a/05-variables.html +++ b/05-variables.html @@ -138,7 +138,7 @@

Associative arrays

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/06-functions.html b/06-functions.html index b343072..d1742c1 100644 --- a/06-functions.html +++ b/06-functions.html @@ -94,7 +94,7 @@

Functions

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/07-classes-1.html b/07-classes-1.html index edbc3c3..23a54bb 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -160,7 +160,7 @@

What's in the class

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/08-classes-2.html b/08-classes-2.html index b62ef70..18542e8 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -149,7 +149,7 @@

Composer

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/09-classes-3.html b/09-classes-3.html index 0664e8e..4e2387f 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -163,7 +163,7 @@

Object Identity

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/10-testing.html b/10-testing.html index a5e524f..0d7634c 100644 --- a/10-testing.html +++ b/10-testing.html @@ -167,7 +167,7 @@

Writing a test

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

diff --git a/index.html b/index.html index 111f1e4..6f3be1a 100644 --- a/index.html +++ b/index.html @@ -94,7 +94,7 @@

Why did I write it?

-

Site built Tue, 25 Feb 2020 20:37.

+

Site built Tue, 25 Feb 2020 20:45.

From 602e5cbf5c720a3b0fb3bdb4483c9c57b16434a1 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Thu, 27 Feb 2020 21:58:35 +0000 Subject: [PATCH 09/40] Update GH Pages based on CircleCI Build 85 [ci skip] --- 01-introduction.html | 8 ++++---- 02-getting-php.html | 16 ++++++++-------- 03-hello-world.html | 12 ++++++------ 04-http.html | 6 +++++- 05-variables.html | 20 ++++++++++---------- 06-functions.html | 11 ++++++----- 07-classes-1.html | 30 ++++++++++++++++-------------- 08-classes-2.html | 25 ++++++++++++++----------- 09-classes-3.html | 31 +++++++++++++++---------------- 10-testing.html | 40 +++++++++++++++++++++------------------- index.html | 8 ++++---- 11 files changed, 109 insertions(+), 98 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 6f3be1a..6746a55 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -59,13 +59,13 @@

Why did I write it?

(This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory -tutorial to recommend they can work through, but I didn't find anything satisfying.

+tutorial to recommend they can work through, but I didn't find anything satisfying.

The tutorial at php.net appears not to have been updated for several years, -and doesn't even introduce either the function or class keywords. On the other hand it does show PHP mixed with HTML, +and doesn't even introduce the function or class keywords. On the other hand it does show PHP mixed with HTML, which I plan to pretend doesn't exist. I think it's now probably worse than useless.

David Brumbaugh's Learn a New Language: Migrating from JavaScript to PHP -is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what composer is, +is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what Composer is, and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to require the reader to install at least PHP 7.2, and spend little if any time on older versions.

PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good @@ -94,7 +94,7 @@

Why did I write it?

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/02-getting-php.html b/02-getting-php.html index 0ecfbf4..e477714 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -53,29 +53,29 @@

Getting PHP

online at 3v4l, but to work through this tutorial you should have PHP installed on your computer.

Installation

First check if you already have PHP installed. Open your command-line prompt, and type php --v. If you have PHP, you -should see something like the following:

+should see something like:

PHP 7.4.2 (cli) (built: Jan 23 2020 11:21:30) ( NTS )
 Copyright (c) The PHP Group
 Zend Engine v3.4.0, Copyright (c) Zend Technologies
     with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
-

Check the first two parts of the version number, e.g. 7.4 above. This is the current version of PHP. Supported older -versions are 7.3 and 7.2. If you have an older version you will need to upgrade before using this tutorial.

+

Check the version number - ideally it should be 7.4.x but at minimum to follow this tutorial it needs to be at least +7.2.

Very few people download PHP directly from php.net. If you work with PHP developers you may want to check where they install their PHP packages from and do the same. Installation methods vary with your operating system:

Linux

-

On Linux, use your package manager to install PHP, e.g. with the sudo apt install php command on Ubuntu, or Debian, and +

On Linux, use your package manager to install PHP, e.g. with the sudo apt install php command on Ubuntu or Debian, and sudo dnf -y install php-cli on Fedora. However these may not give you a recent enough version of PHP. You can get more up to date packages for Ubuntu from Ondřej Surý for Ubuntu or from Remi's RPM Repository for Red Hat, CentOs and Fedora.

Macintosh

Apple supplies PHP as part of OS X, but this is 7.1, and you need at least 7.2. The best way to get that is probably through Homebrew. If you don't have it, first install the Homebrew package manager by following the instructions at -brew.sh, and then enter the command brew install php && brew link php.

+brew.sh, and then enter the command brew install php && brew link php.

Windows

-

I personally don't have a Windows machine, but I think the easiest way to set up PHP on Windows is as part of the +

I personally don't have a Windows machine, but I think the easiest way to set up PHP on Windows may be as part of the XAMPP package. Download and run the installer from Apache Friends. This package bundles PHP along with the Apache web server, MariaDB database server, and the perl language. Xampp is also available -for Linux and Macintosh.

+for Linux and Macintosh.

Run php -v again. Hopefully you will now have version 7.2 or later.

@@ -92,7 +92,7 @@

Windows

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/03-hello-world.html b/03-hello-world.html index 55c47f9..104847a 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -49,20 +49,20 @@

PHP as a Second Language

Hello, world.

-

At this point we're ready to start writing in PHP. Make a new folder for your PHP scripts.

-

If you have a favourite text editor or integrated development environment, such as vim, atom, or vs-code you may want to +

At this point we're ready to start writing in PHP. Make a new folder for your PHP code.

+

If you have a favourite text editor or integrated development environment, such as Vim, Atom, or VS Code you may want to stick with that, but the best tool for editing PHP code is almost certainly JetBrains' PhpStorm. PhpStorm is free for 30 days, but will demand money after that.

-

Make a new file called hello.php, and type in the following:

+

Make a new file called hello.php with your editor or IDE of choice, and type the following:

<?php declare(strict_types=1);
 
 echo "Hello, world.\n";
-

Save the file, and go to your command line. Navigate to your PHP scripts folder, and run your first PHP program by +

Save the file, and go to your command line. Navigate to your PHP code folder, and run it by typing php hello.php. You should see:

$ php hello.php
 Hello, world
 $
-

Every PHP file should start with <?php declare(strict_types=1); . This tells the PHP interpreter that you're writing +

Every PHP file should start with <?php declare(strict_types=1);. <?php tells the PHP interpreter that you're writing PHP, and strict_types tells PHP not to try to guess what you mean so much. Historically PHP has tended to be very loose, and prefer to make the best guess of what's required if it isn't clear instead of giving up. That's probably good for writing a website one page at a time, but for applications we need the computer to stop and tell us what's wrong @@ -84,7 +84,7 @@

Hello, world.

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/04-http.html b/04-http.html index e71dea7..8b71404 100644 --- a/04-http.html +++ b/04-http.html @@ -56,6 +56,10 @@

HTTP

Point your browser at http://localhost:8080/hello.php, and you should see "Hello, world.".

Go back to your command line and press ctrl-c to shut down the server.

+

This tutorial treats PHP as a general purpose programming language - we won't focus on the specifics of running in a web +server. In a big web application only a small part of the code may need to deal with getting data in and out through +HTTP, and usually this will be abstracted away to some extent by a framework like Symfony or Laravel, or a CMS like +Wordpress or Drupal.

@@ -71,7 +75,7 @@

HTTP

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/05-variables.html b/05-variables.html index c10cdbb..fdae652 100644 --- a/05-variables.html +++ b/05-variables.html @@ -61,10 +61,10 @@

Variables, arrays and loops

Arrays and loops

PHP has a very versatile built-in type called array. You're unlikely to find much PHP code that doesn't use arrays extensively, but they are easy to overuse at the cost of other more expressive types. Despite the name, a PHP array -isn't really an array as you may know it from other languages. A PHP array is an ordered iterable dictionary, with keys +isn't really an array as you may know it from other languages. A PHP array is an ordered iterable map, with keys and values. The keys may be strings or integers, and by default will be sequential integers starting at zero. The values can be anything that could go in a variable, including more arrays.

-

An array is not an object in PHP — we will get on to objects later.

+

An array is not an object in PHP. We will cover objects later.

Let's edit our script to declare an array and iterate through it:

<?php declare(strict_types=1);
 
@@ -77,7 +77,7 @@ 

Arrays and loops

$dwarfPlanet = 'Pluto'; echo "Hello, $dwarfPlanet.\n";

If you run this you should see:

-
$ php hello.php 
+
$ php hello.php
 Hello, Mercury.
 Hello, Venus.
 Hello, Earth.
@@ -88,8 +88,8 @@ 

Arrays and loops

Hello, Neptune. Hello, Pluto.
-

foreach assigns each value from the array to the $planet variable in turn. We edit the script to ask it to give us -the numeric keys that were implicitly set on line 3:

+

foreach assigns each value from the array to the $planet variable in turn. We edit the script to print keys as well +as values:

<?php declare(strict_types=1);
 
 $planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'];
@@ -101,10 +101,10 @@ 

Arrays and loops

$dwarfPlanet = 'Pluto'; echo "Hello, $dwarfPlanet.\n";

The PHP manual lists 81 functions for manipulating arrays. For now let's -just try one: natsort. Add new line before foreach:

-
natsort($planets);
-

Re-run the script - the planets are now listed in alphabetical order. But notice that the array keys have not changed - -Mercury is still planet number 0, it's just that 0 now happens to come after 3. PHP array keys can come in any +try one: array_reverse. Add new line before foreach:

+
$planets = array_reverse($planets, true);
+

Re-run the script - the planets are now listed in reverse order. But notice that the array keys have not changed - +Mercury is still planet number 0, it's just that 0 now comes last. PHP array keys can come in any order.

Associative arrays

We can also assign array keys explicitly. When we're interested in the keys of an array we call it an @@ -138,7 +138,7 @@

Associative arrays

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/06-functions.html b/06-functions.html index d1742c1..ce059e9 100644 --- a/06-functions.html +++ b/06-functions.html @@ -49,15 +49,16 @@

PHP as a Second Language

Functions

-

PHP comes with hundreds of built in functions, to sort arrays, find the length of strings, match regexes, or even -get the timestamp corresponding to midnight on Easter of a given year, -you will inevitably want to define your own functions. Function definitions look like this:

+

PHP comes with hundreds of built in functions, to sort arrays, find the +length of strings, match regexes, or even get the timestamp corresponding to midnight on Easter of a given +year, but you will inevitably want to define your own functions. +Function definitions look like this:

function getGreeting(string $planetName): string
 {
     return "Hello, $planetName.\n";
 }

Notice the type declarations, string and : string. Strictly speaking these are optional, but you should add -them whenever you can. Like Typescript, PHP is a gradually typed language. However unlike Typescript, which does +them whenever you can. PHP is a gradually typed language, like TypeScript. However unlike Typescript, which does type checking in the compiler, PHP applies type checking only when the relevant part of your program runs. Let's see an example:

<?php declare(strict_types=1);
@@ -94,7 +95,7 @@ 

Functions

-

Site built Tue, 25 Feb 2020 20:45.

+

Site built Thu, 27 Feb 2020 21:58.

diff --git a/07-classes-1.html b/07-classes-1.html index 23a54bb..90d3f70 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -51,7 +51,7 @@

PHP as a Second Language

Classes and Objects

PHP supports class-based object oriented programming, heavily influenced by Java and similar languages. This is different to the prototype based OO in JavaScript.

-

In the sort of PHP code I write almost 100% of the code is in a project is in classes - some classes are used to make +

In the sort of PHP code I write almost 100% of the code in a project is in classes - some classes are used to make objects, and others may just be convenient wrappers around groups of functions.

In PHP every object is an instance of a class, so you have to have a class before you can have an object. Let's write a class to let us make Planet objects. How to write classes changed a bit in PHP 7.4. Enter the @@ -66,7 +66,7 @@

Classes and Objects

private float $populationSize; - public function __construct(string $name, float $populationSize) + public function __construct(string $name, float $populationSize) { $this->name = $name; $this->populationSize = $populationSize; @@ -95,9 +95,10 @@

Older PHP Versions

/** * @var float */ - private float $populationSize;
+ private $populationSize;

These DocBlocks are ignored by the PHP engine, but they are very useful for us, and many tools and IDEs will read them. -The code inside the docblock is written in the PHPDoc language.

+The code inside the docblock is written in the PHPDoc +language.

Running the code

Run php Planet.php. You should see no output - a class by itself doesn't do anything. We will write code to use this class on the next page.

@@ -113,28 +114,29 @@

What's in the class

Planet is a final class. This prevents any other classes being written as subclasses of Planet. Subclassing is beyond the scope of this tutorial, but for now we can say that it adds significant complexity, and if we don't need it we should probably avoid it. It's therefore a good practice to make classes final by default - we can always delete the -word final if we ever find we do need to make a subclasses of Planet.

+word final if we ever find we do need to make a subclasses of Planet.

  • Planet has name and populationSize properties. When we create Planet objects every object will have its own copy -of these properties. private is the properties visibility - that means that the properties can only be directly read -or written by code within the Planet class. In the PHP 7.4 code they are typed properties, which that PHP will +of these properties. The properties have private visibility - that means that the properties can only be directly read +or written by code within the Planet class.

    +

    In the PHP 7.4 code they are typed properties, so PHP will do a type check at run time whenever we assign values to the properties, and it will only allow us to assign strings of -text and and floating point numbers - attempting to assign anything else would a fatal error.

    -

    We would also get a fatal error if we tried to read these typed properties before they are initialised.

    +text and and floating point numbers - attempting to assign anything else would cause a fatal error.

    +

    We would also get a fatal error if we tried to read these typed properties before assigning values to them.

  • -

    Next we have three functions, also known as methods. These all have public visibility, which means we can call them from anywhere.

    +

    Next we have three class functions, also known as methods. These all have public visibility, which means we can +call them from anywhere.

    Functions whose names start with __ are considered Magic Methods in PHP - they have special meanings given by the language. __construct is the Constructor, and will be automatically called whenever we create a Planet object with the new keyword.

    Finally we have our two getter functions. Since the properties are private, these public functions are needed to allow -code outside the class to read the properties. By keeping the properties private and creating getters but not setters -we can create an immutable object. It's verbose, but it's a lot easier to understand what's happening in a big project +code outside the class to read the properties. It's verbose, but it's a lot easier to understand what's happening in a big project with a class like this than it would be if the properties were public and code from lots of other places could be writing to them.

    These functions will be run with a given object instance of the class. The $this variable will refer to that -object. We use the arrow -> operator to access the properties and methods of any object.

    +object. We use the arrow -> operator to access the properties and methods of any object.

    Having getters also means that if we later want to change the class - perhaps to replace the $populationSize property with an array that holds details of every person on the planet - we can edit the code inside the getter function and make it return the size of the array. Code that uses this class wouldn't have to be @@ -160,7 +162,7 @@

    What's in the class

    -

    Site built Tue, 25 Feb 2020 20:45.

    +

    Site built Thu, 27 Feb 2020 21:58.

    diff --git a/08-classes-2.html b/08-classes-2.html index 18542e8..e940486 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -54,8 +54,8 @@

    Classes Part 2

    PHP works by executing whatever script we give it from beginning to end. It won't run anything inside a class unless we that script tells it to, so every PHP program needs at least one line that isn't part of any class as an entry-point. There is no equivalent to the main function of languages like C and Java.

    -

    By convention, and to follow the PSR-1 coding standard, we always put the entry point in a separate file to the -class declaration.

    +

    By convention, and to follow the PSR-1 coding standard, we always put the entry +point in a separate file to the class declaration.

    Let's write a simple script to create a planet and print out its details. Since at the moment Planet is just a data holder the script won't be too exiting.

    Write the following in a file called start.php

    @@ -66,12 +66,12 @@

    Classes Part 2

    $planet = new Planet('Neptune', 0); echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n"; -

    The new keyword creates objects instances from classes, and automatically runs any constructor with the arguments we pass.

    +

    The new keyword creates objects instances from classes, and automatically calls any constructor the class has.

    We can try running this now but it won't work just yet, because we need to link it up with Planet.php. When you type php start.php you should see PHP Fatal error: Uncaught Error: Class 'Planet' not found.

    Linking files together

    There are two main ways to link files together. The old way is require_once, and the new ways is composer. We'll -start with require_once, but for all but the simplest of scripts we will want to use composer.

    +start with require_once.

    Require_once

    Edit start.php to make it look like this:

    <?php declare(strict_types=1);
    @@ -85,14 +85,15 @@ 

    Require_once

    echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";

    Run the script again, and you should now see Planet Neptune has a population of 0.. The require_once statement tells PHP to process the contents of the given file as if it had been pasted in to the current script, ignoring -the <?php opening tag and the declare. The once part means that if we require the same file more than once PHP will -skip it on the second and subsequent times. That's what want for a class - once the class is loaded there's no need to -load it again, even if multiple parts of our program have to declare that they need that class.

    +the <?php opening tag and the declare. The once part means that if we require_once the same file more than once +PHP will skip it on the second and subsequent times. That's what want for a class - once the class is loaded there's no +need to load it again, even if multiple parts of our program have to declare that they need that class.

    __DIR__ is a PHP magic constant that refers to the directory of whatever file its used in. The dot . is PHP's string concatenation operator.

    But adding a require_once statement every time we need to use a class can quickly become tedious. It's what we all -mostly did until around 2015, when the Composer dependency management tool became popular, even prompting a rare -mention for PHP in the ThoughtWorks Technology Radar.

    +mostly did until around 2015, when the Composer dependency management tool became popular, even prompting a rare +mention for PHP in the ThoughtWorks Technology Radar. Nowadays we +almost always want to use Composer.

    Composer

    Composer is primarily a tool to help you add third party libraries and frameworks to your PHP projects, but since it includes code to help us load the classes those libraries declare it makes sense to also use it to help us load our own @@ -105,7 +106,7 @@

    Composer

    to the class not found error we had before.

    Create a subdirectory src and move Planet.php inside src. It's generally a good idea to have this to keep the bulk of our source code separate from everything else in our project, e.g. the entry point file, any docs we might want to write, -tool config etc.

    +tool config etc.

    Composer works on a project-by-project basis. To set it up for your a project, you need to create a composer.json file. To start with, just put an empty json object in this file:

    {
    @@ -133,6 +134,8 @@ 

    Composer

    As long as we keep our file names matching our class names, Composer will automatically load any class we need, and only when we need it.

    +

    Of course technically we haven't got rid of the require_once statement, but by requiring the autoloader we won't +need to add any more require statements, however classes we use in our program.

    If you run php start.php you should once again learn the population of Neptune.

    @@ -149,7 +152,7 @@

    Composer

    -

    Site built Tue, 25 Feb 2020 20:45.

    +

    Site built Thu, 27 Feb 2020 21:58.

    diff --git a/09-classes-3.html b/09-classes-3.html index 4e2387f..a5d3c5f 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -62,7 +62,7 @@

    Static methods

    private float $populationSize; - public function __construct(string $name, float $populationSize) + public function __construct(string $name, float $populationSize) { $this->name = $name; $this->populationSize = $populationSize; @@ -83,9 +83,9 @@

    Static methods

    return new self('Earth', 7.7 * 10**9); } } -

    The self keyword refers to whatever class it's written in. It's more convenient to write self than to repeat Planet many times.

    @@ -98,22 +98,21 @@

    Static methods

    $planet = Planet::Earth(); echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n"; -

    The double colon is officially called the Scope Resolution Operator. It access properties and methods of classes -without going through an object. In this case our method returns an instance of the class, but it could -do anything.

    +

    The double colon is the Scope Resolution Operator. It accesses static methods (and properties) of classes - there is +no need to have an object first. In this case our method returns an instance of the class, but it could do anything.

    Object Identity

    A PHP variable can't actually hold an object - instead it holds an object identifier, also known as a reference.

    -

    To objects created the same way, with the same properties will have distinct identities. But if one object is created -and then its assigned to two variables, they will both refer hold identifiers for the same object. This becomes -important when we make our objects mutable. This extra complexity is a good reason to prefer immutable objects, but -we will need mutability at times.

    +

    Two objects created the same way, with the same properties will have distinct identities. But if one object is created +and then assigned to two variables, they will both hold identifiers for the same object. This becomes important when we +make our objects mutable. This extra complexity is a good reason to prefer immutable objects, but sometimes we need +mutability.

    Let's add a function to change the world - edit src/Planet.php again, adding the following function inside the class:

       public function receiveImmigrant(): void
        {
            $this->populationSize++;
        }

    void is the return type for functions that don't actually return any information.

    -

    Let's write a script that illustrates identities. Enter the following in 'identities.php'

    +

    Now let's write a script to illustrate object identities. Enter the following in 'identities.php'

    <?php declare(strict_types=1);
     
     namespace PhpAsASecondLanguage;
    @@ -144,10 +143,10 @@ 

    Object Identity

    echo "Population of the same Mercury: {$theSameMercury->getPopulationSize()}.\n";

    We see that $mercury and $theSameMercury are just two names for the same object, while $secondMercury is an entirely separate object with its own properties, lifecycle, hopes and dreams.

    -

    If we use or write a function that accepts an object as a parameter, or returns an object, it's important to be aware -that PHP doesn't make a copy of the object - it just copies the identifier. This means that code within and without -the function can access and potentially change the same object. It's an important part of how communication happens -between the parts of a PHP program, but it can easily get confusing if not managed carefully.

    +

    If a function accepts an object as a parameter, or returns an object, PHP doesn't make a copy of the object - it just +copies the identifier. This means that code within and without the function can access and potentially change the same +object. It's an important part of how communication happens between the parts of a PHP program, but it can easily get +confusing if not managed carefully.

    @@ -163,7 +162,7 @@

    Object Identity

    -

    Site built Tue, 25 Feb 2020 20:45.

    +

    Site built Thu, 27 Feb 2020 21:58.

    diff --git a/10-testing.html b/10-testing.html index 0d7634c..091b766 100644 --- a/10-testing.html +++ b/10-testing.html @@ -58,9 +58,9 @@

    Installing PHPUnit

    Composer also automatically downloads and installs all the libraries that PHPUnit depends on, and the dependencies of its dependencies, etc.

    We use the --dev option because PHPUnit is a tool for developers, and not a library that our program would rely on -in production. If we wanted to prepare a copy of our program to install on a server, we would use the --no-dev option -of composer install to leave out PHPUnit.

    -

    When we ran the require command composer.json edited our composer.json file to record our updated requirements. +in production. If we wanted to prepare a copy of our program to install on a server, we would use +composer install --no-dev install any libraries we need and set up the autoloader but leave out PHPUnit.

    +

    When we ran the require command composer.json edited our composer.json file to record our updated requirements. composer.json should now look like:

    {
         "autoload": {
    @@ -74,14 +74,13 @@ 

    Installing PHPUnit

    }

    The last major release of PHPUnit was 9.0, so composer has assumed we will always want whatever the latest PHPUnit release in the 9 series is. The 10 series is not expected to be compatible with code written for PHPUnit 9, so composer -won't install that unless we edit composer json. Composer works best with dependencies that use semantic versioning, -aka semver.

    +won't install that unless we edit composer json. Composer works best with dependencies that use semantic versioning.

    Composer has also created a new file for us, composer.lock. This has metadata about the exact versions of the packages installed. At the time of writing it shows me that PHPUnit is at version 9.0.1, and I can see the details of 29 other packages that have been installed because PHPUnit depends on them directly or indirectly. The composer show command will output the list of installed packages in a much more consice format.

    Writing a test

    -

    Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

    +

    Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

    <?php declare(strict_types=1);
     
     namespace PhpAsASecondLanguage;
    @@ -104,9 +103,12 @@ 

    Writing a test

    $this->assertSame(1.0, $this->SUT->getPopulationSize()); } }
    -

    The new keyword here is extends. This means that our class is an extension, or subclass of PHPUnit's TestCase class, -which is how PHPUnit is designed to be used. If TestCase has been marked final we wouldn't be able to extend it.

    -

    If you're not on PHP 7.4, remember to remove the Planet property type for the SUT, and replace it with a docbloc as we +

    The first new keyword here is use. This is syntactic sugar that saves us having to spell out the name of the class +PHPUnit\Framework\TestCase in full when we use below.

    +

    We also meet the extends keyword here. This means that our class is an extension, or subclass, of PHPUnit's TestCase +class, which is how PHPUnit is designed to be used. If TestCase has been marked final we wouldn't be able to extend +it.

    +

    If you don't have PHP 7.4, remember to remove the Planet property type of the SUT, and replace it with a docbloc as we did for the properties of Planet itself.

    It's prudent to see a test fail at least once before believing what it says when it passes. To make it fail, comment out $this->populationSize++; in src/Planet.php:

    @@ -115,8 +117,8 @@

    Writing a test

    vendor/bin/phpunit test

    This will search for any filenames ending in Test.php in the test directory. In each test case any public function whose name starts with test is considered a test. For every test PHPUnit creates an instance of the class, calls the -setup function, then calls the test function, records the results, and then throws away the object. So if we had two test -it would run the set up function twice. If an object is referenced only by garbage it is garbage, so when the test case +setup function, then calls the test function, records the results, and then throws away the object. So if we had two +tests it would call setUp twice. Any object referenced only by garbage is garbage, so when the test case object is thrown away the Planet is thrown away too, and any mutations to the planet will not affect the next test.

    The output from PHPUnit should look like:

    PHPUnit 9.0.1 by Sebastian Bergmann and contributors.
    @@ -144,14 +146,14 @@ 

    Writing a test

    OK (1 test, 2 assertions)

    Writing tests is a huge topic, which we can't cover in detail here. PHPUnit has excellent -official documentation. You might choose to do -Test Driven Development (TDD) / Behaviour Driven Development (BDD) and write your tests before writing the -production code that they cover.

    +official documentation. You might want to do +Test Driven Development (TDD) and/or Behaviour Driven Development (BDD) and write your tests before writing the +production code that they cover.

    Some other major test frameworks for PHP are PHPSpec and -Behat, which are both designed around the BDD approach, which -uses the language of executable specifications rather than tests. The major difference is that in PHPSpec, as with -PHPUnit, you code in PHP. In Behat you code in a separate language called gherkin, designed to be readable by project -stakeholders who haven't been trained in programming.

    +Behat. These are both designed around the BDD approach, which +uses the language of executable specifications rather than tests. A major difference between them is that in PHPSpec, +as with PHPUnit, you code in PHP. In Behat you code in a separate language called gherkin, designed to look like English +and be readable by people who haven't been trained in programming.

    @@ -167,7 +169,7 @@

    Writing a test

    -

    Site built Tue, 25 Feb 2020 20:45.

    +

    Site built Thu, 27 Feb 2020 21:58.

    diff --git a/index.html b/index.html index 6f3be1a..6746a55 100644 --- a/index.html +++ b/index.html @@ -59,13 +59,13 @@

    Why did I write it?

    (This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

    I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory -tutorial to recommend they can work through, but I didn't find anything satisfying.

    +tutorial to recommend they can work through, but I didn't find anything satisfying.

    The tutorial at php.net appears not to have been updated for several years, -and doesn't even introduce either the function or class keywords. On the other hand it does show PHP mixed with HTML, +and doesn't even introduce the function or class keywords. On the other hand it does show PHP mixed with HTML, which I plan to pretend doesn't exist. I think it's now probably worse than useless.

    David Brumbaugh's Learn a New Language: Migrating from JavaScript to PHP -is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what composer is, +is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what Composer is, and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to require the reader to install at least PHP 7.2, and spend little if any time on older versions.

    PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good @@ -94,7 +94,7 @@

    Why did I write it?

    -

    Site built Tue, 25 Feb 2020 20:45.

    +

    Site built Thu, 27 Feb 2020 21:58.

    From 56b2c5d9ffebe0921a8881d90d2ffc8d06a54c42 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Thu, 27 Feb 2020 22:28:45 +0000 Subject: [PATCH 10/40] Update GH Pages based on CircleCI Build 88 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- index.html | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 6746a55..01de24b 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -94,7 +94,7 @@

    Why did I write it?

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/02-getting-php.html b/02-getting-php.html index e477714..2b3b997 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -92,7 +92,7 @@

    Windows

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/03-hello-world.html b/03-hello-world.html index 104847a..29b3760 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -84,7 +84,7 @@

    Hello, world.

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/04-http.html b/04-http.html index 8b71404..8619fa7 100644 --- a/04-http.html +++ b/04-http.html @@ -75,7 +75,7 @@

    HTTP

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/05-variables.html b/05-variables.html index fdae652..d25cee8 100644 --- a/05-variables.html +++ b/05-variables.html @@ -138,7 +138,7 @@

    Associative arrays

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/06-functions.html b/06-functions.html index ce059e9..2646a06 100644 --- a/06-functions.html +++ b/06-functions.html @@ -95,7 +95,7 @@

    Functions

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/07-classes-1.html b/07-classes-1.html index 90d3f70..70db1c0 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -162,7 +162,7 @@

    What's in the class

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/08-classes-2.html b/08-classes-2.html index e940486..cc5ac23 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -152,7 +152,7 @@

    Composer

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/09-classes-3.html b/09-classes-3.html index a5d3c5f..4616dae 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -162,7 +162,7 @@

    Object Identity

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/10-testing.html b/10-testing.html index 091b766..9c029b5 100644 --- a/10-testing.html +++ b/10-testing.html @@ -169,7 +169,7 @@

    Writing a test

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    diff --git a/index.html b/index.html index 6746a55..01de24b 100644 --- a/index.html +++ b/index.html @@ -94,7 +94,7 @@

    Why did I write it?

    -

    Site built Thu, 27 Feb 2020 21:58.

    +

    Site built Thu, 27 Feb 2020 22:28.

    From 52a77b24021337f7797ae1c7e2dfd75756c0f597 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 15:37:49 +0000 Subject: [PATCH 11/40] Update GH Pages based on CircleCI Build 91 [ci skip] --- 01-introduction.html | 3 +- 02-getting-php.html | 3 +- 03-hello-world.html | 3 +- 04-http.html | 3 +- 05-variables.html | 3 +- 06-functions.html | 3 +- 07-classes-1.html | 3 +- 08-classes-2.html | 3 +- 09-classes-3.html | 3 +- 10-testing.html | 3 +- 11-databases.html | 246 +++++++++++++++++++++++++++++++++++++++++++ index.html | 3 +- 12 files changed, 268 insertions(+), 11 deletions(-) create mode 100644 11-databases.html diff --git a/01-introduction.html b/01-introduction.html index 01de24b..33f7ad9 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -94,7 +95,7 @@

    Why did I write it?

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/02-getting-php.html b/02-getting-php.html index 2b3b997..5fc5cd3 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -92,7 +93,7 @@

    Windows

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/03-hello-world.html b/03-hello-world.html index 29b3760..6c774a8 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -84,7 +85,7 @@

    Hello, world.

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/04-http.html b/04-http.html index 8619fa7..03bf4f8 100644 --- a/04-http.html +++ b/04-http.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -75,7 +76,7 @@

    HTTP

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/05-variables.html b/05-variables.html index d25cee8..3556e4e 100644 --- a/05-variables.html +++ b/05-variables.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -138,7 +139,7 @@

    Associative arrays

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/06-functions.html b/06-functions.html index 2646a06..232e011 100644 --- a/06-functions.html +++ b/06-functions.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -95,7 +96,7 @@

    Functions

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/07-classes-1.html b/07-classes-1.html index 70db1c0..3495d30 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -162,7 +163,7 @@

    What's in the class

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/08-classes-2.html b/08-classes-2.html index cc5ac23..536f823 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -152,7 +153,7 @@

    Composer

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/09-classes-3.html b/09-classes-3.html index 4616dae..13ae525 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -162,7 +163,7 @@

    Object Identity

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/10-testing.html b/10-testing.html index 9c029b5..e10b95b 100644 --- a/10-testing.html +++ b/10-testing.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -169,7 +170,7 @@

    Writing a test

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    diff --git a/11-databases.html b/11-databases.html new file mode 100644 index 0000000..57ce192 --- /dev/null +++ b/11-databases.html @@ -0,0 +1,246 @@ + + + + + + + PHP as a Second Language + + + + + + + + + + + + +
    +
    DRAFT
    +

    PHP as a Second Language

    + +
    +

    Databases

    +

    PHP applications often connect to databases. This is even harder to avoid in PHP than it would be in other languages +you can run on a web server like JS, Java, or C#, because PHP has a share-nothing architecture. That means that the +code dealing with each request runs in isolation, and does not share any objects or variables with other requests. At +the end of the request-response cycle all stack frames are unwound and all objects are garbage.

    +

    So if your program needs to persist anything from one page to the next, a database is a natural choice.

    +

    For simplicity, we will use SQLite. This is not a database server that you connect to, +but a full featured SQL database engine supplied as a C library, and available as an add-on module for PHP. An SQLite +database is just a file.

    +

    The details of SQL (structured query language), the programming language for defining and querying databases, are beyond +the scope of this tutorial. We will see some SQL code, but as far as PHP is concerned they are just strings to send to +the database engine.

    +

    Install the SQLite PHP Module

    +

    We will use our SQLite database via PHP's PHP Data Objects (PDO) extension, which provides a consistent interface for +accessing many different DB types.

    +

    First check if the necessary PHP modules are installed. Run php -i | grep sqlite. If you have the module set up, +you should see a line like "PDO drivers => sqlite". There may be other drivers listed alongside sqlite.

    +

    If you don't have the PDO SQLite module, how to install it will depend on your OS and how you installed PHP.

    +

    Linux

    +

    If you installed PHP through your package manager, there should be an SQLite module available in the same place. Make +sure you get the module that matches your PHP version number. For instance, on Debian or Ubuntu search your repository +with apt-cache search php | grep sqlite. Once you've found the package name, e.g. php7.4-sqlite3 install it with +a command such as sudo apt install php7.4-sqlite3.

    +

    Mac

    +

    If you installed PHP via homebrew, I think should automatically have come with SQLite built in and enabled.

    +

    Windows

    +

    If you installed PHP as part of XAMPP this should have SQLite enabled by default.

    +

    Creating a database

    +

    First, let's write a PHP script src/create-database.php to create a new database with one table:

    +
    <?php declare(strict_types=1);
    +
    +namespace PhpAsASecondLanguage;
    +use PDO;
    +
    +$filename =__DIR__ . "/database.sqlite";
    +
    +file_put_contents($filename, '');
    +
    +$connection = new PDO("sqlite:".$filename);
    +
    +$connection->query('
    +    CREATE TABLE planets (
    +        id INTEGER PRIMARY KEY,
    +        name text,
    +        population_size INTEGER
    +    );
    +'
    +);
    +

    Run the script with php create-database.php. It should create a new binary file database.sqlite.

    +

    file_put_contents writes a string to a file, creating the file if it already exist. We're using here simply to create +a completely empty file.

    +

    The PDO class is supplied by the PDO extension. A PDO object represents a connection to a database, and allows us to +send it queries and get back results. When we call the PDO constructor +we pass it a string holding details of the database we want to connect to, known as a DSN. For SQLITE the DSN +consists of sqlite: followed by the absolute file path of our database.

    +

    Querying the database

    +

    Let's write a very small program to put the planets in the database, and let us view info about any planet. First we +will need a class that can insert all the planets. Make a file src/PlanetStore.php

    +
    <?php declare(strict_types=1);
    +
    +namespace PhpAsASecondLanguage;
    +
    +use PDO;
    +
    +final class PlanetStore
    +{
    +    private PDO $connection;
    +
    +    public function __construct(PDO $connection) {
    +        $this->connection = $connection;
    +    }
    +
    +    public function storePlanets(): void
    +    {
    +        $statement = $this->connection->prepare('INSERT INTO planets (name, population_size) values (?, ?);');
    +        foreach ($this->generatePlanets() as $planet) {
    +            $statement->execute([$planet->getName(), $planet->getPopulationSize()]);        
    +        }
    +    }
    +
    +    /** @return Planet[] */
    +    private function generatePlanets(): array
    +    {
    +        return [
    +            new Planet('Mercury', 0),
    +            new Planet('Venus', 0),
    +            new Planet('Earth', 7.7 * 10**9),
    +            new Planet('Mars', 0),
    +            new Planet('Jupiter', 0),
    +            new Planet('Saturn', 0),
    +            new Planet('Uranus', 0),
    +            new Planet('Neptune', 0),
    +        ];
    +    } 
    +}
    +

    And write a script to invoke this class: storePlanets.php:

    +
    <?php declare(strict_types=1);
    +
    +namespace PhpAsASecondLanguage;
    +
    +require_once __DIR__ . '/vendor/autoload.php';
    +
    +use PDO;
    +
    +$planetStore = new PlanetStore(
    +    new PDO("sqlite:". __DIR__ . '/database.sqlite')
    +);
    +
    +$planetStore->storePlanets();
    +

    Run php storePlanets.php. This should add the eight planets to the database. If it works it won't produce any visible +output.

    +

    The most important thing to notice about our code so far is that we didn't concatenate any strings to create queries to +send to the database. Instead we prepared a query, using question marks as placeholders for our data, and then supplied +the values of those parameters separately each time we executed the query. This practice makes our database use much +less error prone and more secure. The database engine knows what exactly what's code that it should interpret and what's +data that it should simply store.

    +

    Now let's write the code to show a planet. First let's add a function to the PlanetStore class to pull a Planet out of +the database:

    +
        public function getPlanet(string $planetName): ?Planet
    +    {
    +        $statement = $this->connection->prepare(
    +            'SELECT name, population_size FROM planets where name = :name;'
    +        );
    +        $statement->bindValue(':name', $planetName);
    +        $statement->execute();
    +
    +        $row = $statement->fetch(PDO::FETCH_ASSOC);
    +
    +        if (! $row) {
    +            return null;
    +        }
    +
    +        return new Planet($row['name'], (float) $row['population_size']);
    +    }
    +

    Notice the return type: ?Planet means that the function may either return an instance of Planet, or the value null. +We can add ? to the beginning of any type name to make it nullable.

    +

    We use (float) to cast or convert the population size data from a string, as it comes back from the sqlite DB, to +a floating point number.

    +

    In this case we have used a named parameter in the database query, instead of a question mark.

    +

    Finally we need to make a PHP script to go between this function and the browser. Call it viewPlanet.php:

    +
    <?php declare(strict_types=1);
    +
    +namespace PhpAsASecondLanguage;
    +
    +require_once __DIR__ . '/vendor/autoload.php';
    +
    +use PDO;
    +
    +$planetStore = new PlanetStore(
    +    new PDO("sqlite:". __DIR__ . '/database.sqlite')
    +);
    +
    +$planet = $planetStore->getPlanet($_GET['name']);
    +
    +header('Content-Type: text/plain');
    +if ($planet === null) {
    +    http_response_code(404);
    +    echo ('Planet not found');
    +    exit();
    +}
    +
    +echo "**********   {$planet->getName()}   **********\n\n";
    +echo "Population: {$planet->getPopulationSize()}\n";
    +

    Notice the $_GET array - PHP automatically fills this so-called superglobals array with any query parameters sent by +the browser. It is available to us anywhere in our program, but it's best to limit where we use it - code that directly +pulls data from superglobals can be hard to test and re-use.

    +

    Run the PHP server:

    +
    php -S localhost:8080
    +

    Open http://localhost:8080/viewPlanet.php?name=Earth in your browser.

    +

    Other Database Engines.

    +

    PDO has drivers for eleven other database engines that you can use +use instead of SQLite. Connecting, sending queries, and receiving rows should work in the same way, but of course the +details of connection strings and SQL code will vary from DB to DB.

    +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/index.html b/index.html index 01de24b..33f7ad9 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,7 @@

    PHP as a Second Language

  • 08-classes-2
  • 09-classes-3
  • 10-testing
  • +
  • 11-databases
  • @@ -94,7 +95,7 @@

    Why did I write it?

    -

    Site built Thu, 27 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 15:37.

    From c45dddd07fd8cbf091663d05c6c7099c0254c71e Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 15:56:27 +0000 Subject: [PATCH 12/40] Update GH Pages based on CircleCI Build 94 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 50 ++++++++++++++++++++++++-------------------- index.html | 2 +- 12 files changed, 38 insertions(+), 34 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 33f7ad9..9e9b4a6 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -95,7 +95,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/02-getting-php.html b/02-getting-php.html index 5fc5cd3..f95accb 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -93,7 +93,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/03-hello-world.html b/03-hello-world.html index 6c774a8..b3d1dc6 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -85,7 +85,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/04-http.html b/04-http.html index 03bf4f8..1b3e9bb 100644 --- a/04-http.html +++ b/04-http.html @@ -76,7 +76,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/05-variables.html b/05-variables.html index 3556e4e..f46fdc1 100644 --- a/05-variables.html +++ b/05-variables.html @@ -139,7 +139,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/06-functions.html b/06-functions.html index 232e011..b6d1d23 100644 --- a/06-functions.html +++ b/06-functions.html @@ -96,7 +96,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/07-classes-1.html b/07-classes-1.html index 3495d30..a67a1ae 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -163,7 +163,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/08-classes-2.html b/08-classes-2.html index 536f823..4f806c4 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -153,7 +153,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/09-classes-3.html b/09-classes-3.html index 13ae525..19173ca 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -163,7 +163,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/10-testing.html b/10-testing.html index e10b95b..6b91e67 100644 --- a/10-testing.html +++ b/10-testing.html @@ -170,7 +170,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/11-databases.html b/11-databases.html index 57ce192..fa4fa50 100644 --- a/11-databases.html +++ b/11-databases.html @@ -51,14 +51,14 @@

    PHP as a Second Language

    Databases

    PHP applications often connect to databases. This is even harder to avoid in PHP than it would be in other languages -you can run on a web server like JS, Java, or C#, because PHP has a share-nothing architecture. That means that the +you can run on a web server like JS, Java, or C#, because PHP has a shared-nothing architecture. That means that the code dealing with each request runs in isolation, and does not share any objects or variables with other requests. At -the end of the request-response cycle all stack frames are unwound and all objects are garbage.

    +the end of the request-response cycle all stack frames are unwound and all objects become garbage.

    So if your program needs to persist anything from one page to the next, a database is a natural choice.

    For simplicity, we will use SQLite. This is not a database server that you connect to, -but a full featured SQL database engine supplied as a C library, and available as an add-on module for PHP. An SQLite -database is just a file.

    -

    The details of SQL (structured query language), the programming language for defining and querying databases, are beyond +but a full featured SQL database engine supplied as a C library, and available as an add-on module for PHP, and the +world's most widely deployed DB engine. An SQLite database is just a file.

    +

    The details of SQL, the programming language for defining and querying databases, are beyond the scope of this tutorial. We will see some SQL code, but as far as PHP is concerned they are just strings to send to the database engine.

    Install the SQLite PHP Module

    @@ -70,10 +70,12 @@

    Install the SQLite PHP Module

    Linux

    If you installed PHP through your package manager, there should be an SQLite module available in the same place. Make sure you get the module that matches your PHP version number. For instance, on Debian or Ubuntu search your repository -with apt-cache search php | grep sqlite. Once you've found the package name, e.g. php7.4-sqlite3 install it with -a command such as sudo apt install php7.4-sqlite3.

    +with:

    +

    apt-cache search php | grep sqlite

    +

    Once you've found the package name, e.g. php7.4-sqlite3 install it with a command such as

    +

    sudo apt install php7.4-sqlite3.

    Mac

    -

    If you installed PHP via homebrew, I think should automatically have come with SQLite built in and enabled.

    +

    If you installed PHP via homebrew, I think will automatically have come with SQLite built in and enabled.

    Windows

    If you installed PHP as part of XAMPP this should have SQLite enabled by default.

    Creating a database

    @@ -81,13 +83,14 @@

    Creating a database

    <?php declare(strict_types=1);
     
     namespace PhpAsASecondLanguage;
    +
     use PDO;
     
     $filename =__DIR__ . "/database.sqlite";
     
     file_put_contents($filename, '');
     
    -$connection = new PDO("sqlite:".$filename);
    +$connection = new PDO("sqlite:" . $filename);
     
     $connection->query('
         CREATE TABLE planets (
    @@ -98,12 +101,13 @@ 

    Creating a database

    ' );

    Run the script with php create-database.php. It should create a new binary file database.sqlite.

    -

    file_put_contents writes a string to a file, creating the file if it already exist. We're using here simply to create +

    file_put_contents writes a string to a file, overwriting the file if it already exists. We're using here to create a completely empty file.

    -

    The PDO class is supplied by the PDO extension. A PDO object represents a connection to a database, and allows us to -send it queries and get back results. When we call the PDO constructor -we pass it a string holding details of the database we want to connect to, known as a DSN. For SQLITE the DSN -consists of sqlite: followed by the absolute file path of our database.

    +

    The PDO class is supplied by the PDO extension. A PDO object represents +a connection to a database, and allows us to send it queries and get back results. When we call the +PDO constructor we pass it a string holding details of the database +we want to connect to, known as a Data Source Name or DSN. For SQLite the DSN consists of 'sqlite:' followed by an +absolute file path.

    Querying the database

    Let's write a very small program to put the planets in the database, and let us view info about any planet. First we will need a class that can insert all the planets. Make a file src/PlanetStore.php

    @@ -144,7 +148,8 @@

    Querying the database

    ]; } } -

    And write a script to invoke this class: storePlanets.php:

    +

    Once again if you don't have PHP 7.4 you will need to remove the PDO property type on the $connection property.

    +

    Now write a script storePlanets.php to use this class:

    <?php declare(strict_types=1);
     
     namespace PhpAsASecondLanguage;
    @@ -158,13 +163,12 @@ 

    Querying the database

    ); $planetStore->storePlanets();
    -

    Run php storePlanets.php. This should add the eight planets to the database. If it works it won't produce any visible -output.

    +

    Run php storePlanets.php. This should add the eight planets to the database. It shouldn't produce any visible output.

    The most important thing to notice about our code so far is that we didn't concatenate any strings to create queries to send to the database. Instead we prepared a query, using question marks as placeholders for our data, and then supplied -the values of those parameters separately each time we executed the query. This practice makes our database use much -less error prone and more secure. The database engine knows what exactly what's code that it should interpret and what's -data that it should simply store.

    +the values of those parameters separately each time we executed the query.

    +

    This practice makes our database use much less error prone and more secure. The database engine knows what exactly +what's code that it should interpret and what's data that it should simply store.

    Now let's write the code to show a planet. First let's add a function to the PlanetStore class to pull a Planet out of the database:

        public function getPlanet(string $planetName): ?Planet
    @@ -212,9 +216,9 @@ 

    Querying the database

    echo "********** {$planet->getName()} **********\n\n"; echo "Population: {$planet->getPopulationSize()}\n";
    -

    Notice the $_GET array - PHP automatically fills this so-called superglobals array with any query parameters sent by +

    Notice the $_GET array - PHP automatically fills this so-called superglobal array with any query parameters sent by the browser. It is available to us anywhere in our program, but it's best to limit where we use it - code that directly -pulls data from superglobals can be hard to test and re-use.

    +pulls data from superglobals can be very hard to test and re-use and understand.

    Run the PHP server:

    php -S localhost:8080

    Open http://localhost:8080/viewPlanet.php?name=Earth in your browser.

    @@ -237,7 +241,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    diff --git a/index.html b/index.html index 33f7ad9..9e9b4a6 100644 --- a/index.html +++ b/index.html @@ -95,7 +95,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 15:37.

    +

    Site built Sat, 29 Feb 2020 15:55.

    From 3414744a9a0e9b28d12cfb2d2747ce0addbf8df0 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 17:35:14 +0000 Subject: [PATCH 13/40] Update GH Pages based on CircleCI Build 98 [ci skip] --- 01-introduction.html | 3 +- 02-getting-php.html | 3 +- 03-hello-world.html | 3 +- 04-http.html | 3 +- 05-variables.html | 3 +- 06-functions.html | 3 +- 07-classes-1.html | 3 +- 08-classes-2.html | 3 +- 09-classes-3.html | 3 +- 10-testing.html | 3 +- 11-databases.html | 3 +- 12-templating.html | 143 +++++++++++++++++++++++++++++++++++++++++++ index.html | 3 +- 13 files changed, 167 insertions(+), 12 deletions(-) create mode 100644 12-templating.html diff --git a/01-introduction.html b/01-introduction.html index 9e9b4a6..4028a7d 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -95,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/02-getting-php.html b/02-getting-php.html index f95accb..2f5875c 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -93,7 +94,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/03-hello-world.html b/03-hello-world.html index b3d1dc6..5362df0 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -85,7 +86,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/04-http.html b/04-http.html index 1b3e9bb..38d8199 100644 --- a/04-http.html +++ b/04-http.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -76,7 +77,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/05-variables.html b/05-variables.html index f46fdc1..30c2af9 100644 --- a/05-variables.html +++ b/05-variables.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -139,7 +140,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/06-functions.html b/06-functions.html index b6d1d23..744036c 100644 --- a/06-functions.html +++ b/06-functions.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -96,7 +97,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/07-classes-1.html b/07-classes-1.html index a67a1ae..bb86f31 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -163,7 +164,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/08-classes-2.html b/08-classes-2.html index 4f806c4..d5d817c 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -153,7 +154,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/09-classes-3.html b/09-classes-3.html index 19173ca..3bbb9b5 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -163,7 +164,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/10-testing.html b/10-testing.html index 6b91e67..abbb90b 100644 --- a/10-testing.html +++ b/10-testing.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -170,7 +171,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/11-databases.html b/11-databases.html index fa4fa50..f8743fa 100644 --- a/11-databases.html +++ b/11-databases.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -241,7 +242,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    diff --git a/12-templating.html b/12-templating.html new file mode 100644 index 0000000..6ec769e --- /dev/null +++ b/12-templating.html @@ -0,0 +1,143 @@ + + + + + + + PHP as a Second Language + + + + + + + + + + + + +
    +
    DRAFT
    +

    PHP as a Second Language

    + +
    +

    Templating

    +

    Our planet viewer works, but it isn't pretty. Let's use some HTML to make it look a little better.

    +

    It has been a common practice to use PHP as a templating language, and even mix PHP and HTML code together in the same +file. While PHP can still be used as a templating language, it isn't a good one, so we won't do that.

    +

    Instead, we will use PHP to prepare whatever data we want to show, and then pass that to a template written in a +different language.

    +

    There are dozens of template engines available as libraries to use in PHP programs, and another good option +is to make a single page application, with all templating done in the browser, and data sent from the server as JSON.

    +

    Twig

    +

    For this tutorial we will write a template in the Twig language, which works with PHP.

    +

    First install Twig in your project by running:

    +
    composer require "twig/twig:^3.0"
    +

    Now let's make our template. Start by writing a page in HTML. For now we'll hard code everything. Make a +'templates' directory, and save the following as 'templates/planet.html.twig':

    +
    <!doctype html>
    +<html>
    +    <head>
    +        <title>Some Planet</title>
    +    </head>
    +    <body>
    +        <h1>Some Planet</h1>
    +        <p>Population: 34601</p>
    +    </body>
    +</html>
    +

    Edit our viewPlanet.php file to make it use this template:

    +
    <?php declare(strict_types=1);
    +
    +namespace PhpAsASecondLanguage;
    +
    +require_once __DIR__ . '/vendor/autoload.php';
    +
    +use PDO;
    +use Twig\Loader\FilesystemLoader;
    +
    +$planetStore = new PlanetStore(
    +    new PDO("sqlite:". __DIR__ . '/database.sqlite')
    +);
    +
    +$templateLoader = new FilesystemLoader(__DIR__ . '/templates/');
    +$twig = new \Twig\Environment($templateLoader);
    +
    +$planet = $planetStore->getPlanet($_GET['name']);
    +
    +header('Content-Type: text/html');
    +if ($planet === null) {
    +    http_response_code(404);
    +    echo ('Planet not found');
    +    exit();
    +}
    +
    +$template = $twig->load('planet.html.twig');
    +
    +echo $template->render();
    +

    If you run the PHP server again and view your site you should see the content of the template. Of course at this point +all we're doing is serving static HTML with extra steps.

    +

    Behind the scenes the Twig engine compiles the template to a PHP class. We don't need to read the class, but this is +useful because it means we can pass PHP objects to it and use their properties and functions. Let's pass our planet +object to the template. Change the last line of 'viewPlanet.php' to:

    +
    echo $template->render(['planet' => $planet]);
    +

    Finally we need to edit 'planet.html.twig'. Since we won't always be reading the template at the same time as the PHP file +that uses it, and neither will any tools and IDEs we might be using, we should add a comment to make it clear that we +expect to have a planet variable, and it will be of type Planet. Add the following to the top of the file:

    +
    {#  @var planet PhpAsASecondLanguage\Planet #}
    +

    In Twig we use double curly brackets to output dynamic data: Replace Some Planet with +{{planet.name}}, and replace 34601 with {{planet.populationSize}}. Twig knows that we mean getName and +getPopulationSize, so we don't have to write those function names out in full.

    +

    If you reload the page you should now see the planet details in their proper places.

    +

    Twig is a full featured special purpose programming language, with features like loops, conditionals, filters, +inheritance, etc, but this is a PHP tutorial, not a Twig tutorial.

    +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/index.html b/index.html index 9e9b4a6..4028a7d 100644 --- a/index.html +++ b/index.html @@ -46,6 +46,7 @@

    PHP as a Second Language

  • 09-classes-3
  • 10-testing
  • 11-databases
  • +
  • 12-templating
  • @@ -95,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 15:55.

    +

    Site built Sat, 29 Feb 2020 17:35.

    From 55490402eb613266cb099aecbef7eb67e2eeea87 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 17:47:31 +0000 Subject: [PATCH 14/40] Update GH Pages based on CircleCI Build 101 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- index.html | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 4028a7d..b1507ea 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -96,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/02-getting-php.html b/02-getting-php.html index 2f5875c..42916bf 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -94,7 +94,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/03-hello-world.html b/03-hello-world.html index 5362df0..f0885e9 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -86,7 +86,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/04-http.html b/04-http.html index 38d8199..727cae6 100644 --- a/04-http.html +++ b/04-http.html @@ -77,7 +77,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/05-variables.html b/05-variables.html index 30c2af9..aa60f39 100644 --- a/05-variables.html +++ b/05-variables.html @@ -140,7 +140,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/06-functions.html b/06-functions.html index 744036c..a0a17d9 100644 --- a/06-functions.html +++ b/06-functions.html @@ -97,7 +97,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/07-classes-1.html b/07-classes-1.html index bb86f31..46620d2 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -164,7 +164,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/08-classes-2.html b/08-classes-2.html index d5d817c..9e25843 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -154,7 +154,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/09-classes-3.html b/09-classes-3.html index 3bbb9b5..ae82775 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -164,7 +164,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/10-testing.html b/10-testing.html index abbb90b..19a42d1 100644 --- a/10-testing.html +++ b/10-testing.html @@ -171,7 +171,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/11-databases.html b/11-databases.html index f8743fa..f7833af 100644 --- a/11-databases.html +++ b/11-databases.html @@ -242,7 +242,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/12-templating.html b/12-templating.html index 6ec769e..765fd58 100644 --- a/12-templating.html +++ b/12-templating.html @@ -134,7 +134,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    diff --git a/index.html b/index.html index 4028a7d..b1507ea 100644 --- a/index.html +++ b/index.html @@ -96,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:35.

    +

    Site built Sat, 29 Feb 2020 17:47.

    From f2782486c97310d4364861c3a25f25b86184e52e Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 17:51:11 +0000 Subject: [PATCH 15/40] Update GH Pages based on CircleCI Build 104 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- index.html | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index b1507ea..10d875b 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -96,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/02-getting-php.html b/02-getting-php.html index 42916bf..8c880f4 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -94,7 +94,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/03-hello-world.html b/03-hello-world.html index f0885e9..cd98aa5 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -86,7 +86,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/04-http.html b/04-http.html index 727cae6..fe15848 100644 --- a/04-http.html +++ b/04-http.html @@ -77,7 +77,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/05-variables.html b/05-variables.html index aa60f39..670efe8 100644 --- a/05-variables.html +++ b/05-variables.html @@ -140,7 +140,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/06-functions.html b/06-functions.html index a0a17d9..7f5d0bc 100644 --- a/06-functions.html +++ b/06-functions.html @@ -97,7 +97,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/07-classes-1.html b/07-classes-1.html index 46620d2..b3c20cd 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -164,7 +164,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/08-classes-2.html b/08-classes-2.html index 9e25843..3bdd203 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -154,7 +154,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/09-classes-3.html b/09-classes-3.html index ae82775..6dfabad 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -164,7 +164,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/10-testing.html b/10-testing.html index 19a42d1..1bbaa1b 100644 --- a/10-testing.html +++ b/10-testing.html @@ -171,7 +171,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/11-databases.html b/11-databases.html index f7833af..a08b096 100644 --- a/11-databases.html +++ b/11-databases.html @@ -242,7 +242,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/12-templating.html b/12-templating.html index 765fd58..1557052 100644 --- a/12-templating.html +++ b/12-templating.html @@ -134,7 +134,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    diff --git a/index.html b/index.html index b1507ea..10d875b 100644 --- a/index.html +++ b/index.html @@ -96,7 +96,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:47.

    +

    Site built Sat, 29 Feb 2020 17:50.

    From 43d9605e529433d55193904c0f0fd8f8d6b54632 Mon Sep 17 00:00:00 2001 From: Barney Laurance Date: Sat, 29 Feb 2020 18:27:59 +0000 Subject: [PATCH 16/40] Create CNAME --- CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 CNAME diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..cdd7147 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +a-moderately-short-php-tutorial.com \ No newline at end of file From b749db12f8acae463a98b7a82362e0e1e96763b9 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 18:38:41 +0000 Subject: [PATCH 17/40] Update GH Pages based on CircleCI Build 108 [ci skip] --- 01-introduction.html | 4 ++- 02-getting-php.html | 4 ++- 03-hello-world.html | 4 ++- 04-http.html | 4 ++- 05-variables.html | 4 ++- 06-functions.html | 4 ++- 07-classes-1.html | 4 ++- 08-classes-2.html | 4 ++- 09-classes-3.html | 4 ++- 10-testing.html | 4 ++- 11-databases.html | 4 ++- 12-templating.html | 4 ++- 13-static-analysis.html | 77 +++++++++++++++++++++++++++++++++++++++++ 14-further-reading.html | 77 +++++++++++++++++++++++++++++++++++++++++ CNAME | 2 +- index.html | 4 ++- 16 files changed, 194 insertions(+), 14 deletions(-) create mode 100644 13-static-analysis.html create mode 100644 14-further-reading.html diff --git a/01-introduction.html b/01-introduction.html index 10d875b..018a7cf 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -96,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/02-getting-php.html b/02-getting-php.html index 8c880f4..6c35d1f 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -94,7 +96,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/03-hello-world.html b/03-hello-world.html index cd98aa5..7e9c951 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -86,7 +88,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/04-http.html b/04-http.html index fe15848..2c72650 100644 --- a/04-http.html +++ b/04-http.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -77,7 +79,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/05-variables.html b/05-variables.html index 670efe8..181b778 100644 --- a/05-variables.html +++ b/05-variables.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -140,7 +142,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/06-functions.html b/06-functions.html index 7f5d0bc..524d44c 100644 --- a/06-functions.html +++ b/06-functions.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -97,7 +99,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/07-classes-1.html b/07-classes-1.html index b3c20cd..2be9a75 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -164,7 +166,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/08-classes-2.html b/08-classes-2.html index 3bdd203..5d47065 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -154,7 +156,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/09-classes-3.html b/09-classes-3.html index 6dfabad..7d2561f 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -164,7 +166,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/10-testing.html b/10-testing.html index 1bbaa1b..2e7e121 100644 --- a/10-testing.html +++ b/10-testing.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -171,7 +173,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/11-databases.html b/11-databases.html index a08b096..3ed65e6 100644 --- a/11-databases.html +++ b/11-databases.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -242,7 +244,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/12-templating.html b/12-templating.html index 1557052..96b5e68 100644 --- a/12-templating.html +++ b/12-templating.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -134,7 +136,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    diff --git a/13-static-analysis.html b/13-static-analysis.html new file mode 100644 index 0000000..4c80e94 --- /dev/null +++ b/13-static-analysis.html @@ -0,0 +1,77 @@ + + + + + + + PHP as a Second Language + + + + + + + + + + + + +
    +
    DRAFT
    +

    PHP as a Second Language

    + +
    + +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/14-further-reading.html b/14-further-reading.html new file mode 100644 index 0000000..4c80e94 --- /dev/null +++ b/14-further-reading.html @@ -0,0 +1,77 @@ + + + + + + + PHP as a Second Language + + + + + + + + + + + + +
    +
    DRAFT
    +

    PHP as a Second Language

    + +
    + +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/CNAME b/CNAME index cdd7147..4108d97 100644 --- a/CNAME +++ b/CNAME @@ -1 +1 @@ -a-moderately-short-php-tutorial.com \ No newline at end of file +a-moderately-short-php-tutorial.com diff --git a/index.html b/index.html index 10d875b..018a7cf 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,8 @@

    PHP as a Second Language

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • +
  • 14-further-reading
  • @@ -96,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 17:50.

    +

    Site built Sat, 29 Feb 2020 18:38.

    From da7739ec143003fbe77360c5477c532bbec2f347 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 20:43:27 +0000 Subject: [PATCH 18/40] Update GH Pages based on CircleCI Build 111 [ci skip] --- 01-introduction.html | 7 ++-- 02-getting-php.html | 7 ++-- 03-hello-world.html | 7 ++-- 04-http.html | 7 ++-- 05-variables.html | 7 ++-- 06-functions.html | 7 ++-- 07-classes-1.html | 11 +++--- 08-classes-2.html | 15 ++++---- 09-classes-3.html | 13 ++++--- 10-testing.html | 13 ++++--- 11-databases.html | 15 ++++---- 12-templating.html | 11 +++--- 13-static-analysis.html | 77 ----------------------------------------- 14-further-reading.html | 7 ++-- index.html | 7 ++-- 15 files changed, 60 insertions(+), 151 deletions(-) delete mode 100644 13-static-analysis.html diff --git a/01-introduction.html b/01-introduction.html index 018a7cf..82ad769 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -98,7 +97,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/02-getting-php.html b/02-getting-php.html index 6c35d1f..c28b616 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -96,7 +95,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/03-hello-world.html b/03-hello-world.html index 7e9c951..8bdafba 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -88,7 +87,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/04-http.html b/04-http.html index 2c72650..98c3f7a 100644 --- a/04-http.html +++ b/04-http.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -79,7 +78,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/05-variables.html b/05-variables.html index 181b778..673dace 100644 --- a/05-variables.html +++ b/05-variables.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -142,7 +141,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/06-functions.html b/06-functions.html index 524d44c..c91ab42 100644 --- a/06-functions.html +++ b/06-functions.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -99,7 +98,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/07-classes-1.html b/07-classes-1.html index 2be9a75..748199b 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -62,7 +61,7 @@

    Classes and Objects

    following in a file called Planet.php:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     final class Planet
     {
    @@ -112,7 +111,7 @@ 

    What's in the class

  • The entire file is in a namespace. This is useful to help distinguish our code from other people's code, and to distinguish between submodules when our program gets bigger. We will keep all our code in this namespace. The -namespace is effectively a prefix, so the full name of the class is \PhpAsASecondLanguage\Planet.

    +namespace is effectively a prefix, so the full name of the class is \AModeratelyShortPhpTutorial\Planet.

  • Planet is a final class. This prevents any other classes being written as subclasses of Planet. Subclassing is @@ -166,7 +165,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

  • diff --git a/08-classes-2.html b/08-classes-2.html index 5d47065..73bb7a5 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -65,7 +64,7 @@

    Classes Part 2

    Write the following in a file called start.php

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     $planet = new Planet('Neptune', 0);
     
    @@ -80,7 +79,7 @@ 

    Require_once

    Edit start.php to make it look like this:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__ . '/Planet.php';
     
    @@ -122,14 +121,14 @@ 

    Composer

    {
         "autoload": {
             "psr-4": {
    -            "PhpAsASecondLanguage\\": "src/"
    +            "AModeratelyShortPhpTutorial\\": "src/"
             }
         }
     }

    Re-run composer install, and then edit start.php to require Composer's autoloader:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__. '/vendor/autoload.php';
     
    @@ -156,7 +155,7 @@ 

    Composer

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/09-classes-3.html b/09-classes-3.html index 7d2561f..0c208be 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -58,7 +57,7 @@

    Static methods

    instance are called static methods. Let's add a static method to the Planet class in src/Planet.php:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     final class Planet
     {
    @@ -96,7 +95,7 @@ 

    Static methods

    And let's edit start.php:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__. '/vendor/autoload.php';
     
    @@ -119,7 +118,7 @@ 

    Object Identity

    Now let's write a script to illustrate object identities. Enter the following in 'identities.php'

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__. '/vendor/autoload.php';
     
    @@ -166,7 +165,7 @@ 

    Object Identity

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/10-testing.html b/10-testing.html index 2e7e121..b804dab 100644 --- a/10-testing.html +++ b/10-testing.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -69,7 +68,7 @@

    Installing PHPUnit

    {
         "autoload": {
             "psr-4": {
    -            "PhpAsASecondLanguage\\": "src/"
    +            "AModeratelyShortPhpTutorial\\": "src/"
             }
         },
         "require-dev": {
    @@ -87,7 +86,7 @@ 

    Writing a test

    Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     use PHPUnit\Framework\TestCase;
     
    @@ -133,7 +132,7 @@ 

    Writing a test

    There was 1 failure: -1) PhpAsASecondLanguage\PlanetTest::test_it_can_accept_immigrant +1) AModeratelyShortPhpTutorial\PlanetTest::test_it_can_accept_immigrant Failed asserting that 0.0 is identical to 1.0. /tmp/composerPlayground/test/PlanetTest.php:20 @@ -173,7 +172,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/11-databases.html b/11-databases.html index 3ed65e6..8f4b958 100644 --- a/11-databases.html +++ b/11-databases.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -85,7 +84,7 @@

    Creating a database

    First, let's write a PHP script src/create-database.php to create a new database with one table:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     use PDO;
     
    @@ -116,7 +115,7 @@ 

    Querying the database

    will need a class that can insert all the planets. Make a file src/PlanetStore.php

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     use PDO;
     
    @@ -155,7 +154,7 @@ 

    Querying the database

    Now write a script storePlanets.php to use this class:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__ . '/vendor/autoload.php';
     
    @@ -198,7 +197,7 @@ 

    Querying the database

    Finally we need to make a PHP script to go between this function and the browser. Call it viewPlanet.php:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__ . '/vendor/autoload.php';
     
    @@ -244,7 +243,7 @@ 

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/12-templating.html b/12-templating.html index 96b5e68..ca4c929 100644 --- a/12-templating.html +++ b/12-templating.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -79,7 +78,7 @@

    Twig

    Edit our viewPlanet.php file to make it use this template:

    <?php declare(strict_types=1);
     
    -namespace PhpAsASecondLanguage;
    +namespace AModeratelyShortPhpTutorial;
     
     require_once __DIR__ . '/vendor/autoload.php';
     
    @@ -114,7 +113,7 @@ 

    Twig

    Finally we need to edit 'planet.html.twig'. Since we won't always be reading the template at the same time as the PHP file that uses it, and neither will any tools and IDEs we might be using, we should add a comment to make it clear that we expect to have a planet variable, and it will be of type Planet. Add the following to the top of the file:

    -
    {#  @var planet PhpAsASecondLanguage\Planet #}
    +
    {#  @var planet AModeratelyShortPhpTutorial\Planet #}

    In Twig we use double curly brackets to output dynamic data: Replace Some Planet with {{planet.name}}, and replace 34601 with {{planet.populationSize}}. Twig knows that we mean getName and getPopulationSize, so we don't have to write those function names out in full.

    @@ -136,7 +135,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/13-static-analysis.html b/13-static-analysis.html deleted file mode 100644 index 4c80e94..0000000 --- a/13-static-analysis.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - PHP as a Second Language - - - - - - - - - - - - -
    -
    DRAFT
    -

    PHP as a Second Language

    - -
    - -
    - -
    - Copyright Barney Laurance 2020 -
    - - - -
    - - \ No newline at end of file diff --git a/14-further-reading.html b/14-further-reading.html index 4c80e94..e34b3d2 100644 --- a/14-further-reading.html +++ b/14-further-reading.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -68,7 +67,7 @@

    PHP as a Second Language

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    diff --git a/index.html b/index.html index 018a7cf..82ad769 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - PHP as a Second Language + A Moderately Short PHP Tutorial
    DRAFT
    -

    PHP as a Second Language

    +

    A Moderately Short PHP Tutorial

    @@ -98,7 +97,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 18:38.

    +

    Site built Sat, 29 Feb 2020 20:43.

    From 9b4a3687797a5b52fa47b5a5ebe5f094636d87b6 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 22:28:53 +0000 Subject: [PATCH 19/40] Update GH Pages based on CircleCI Build 114 [ci skip] --- 01-introduction.html | 3 +- 02-getting-php.html | 3 +- 03-hello-world.html | 3 +- 04-http.html | 3 +- 05-variables.html | 3 +- 06-functions.html | 3 +- 07-classes-1.html | 3 +- 08-classes-2.html | 3 +- 09-classes-3.html | 3 +- 10-testing.html | 3 +- 11-databases.html | 5 +- 12-templating.html | 5 +- 13-static-analysis.html | 142 ++++++++++++++++++++++++++++++++++++++++ 14-further-reading.html | 3 +- index.html | 3 +- 15 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 13-static-analysis.html diff --git a/01-introduction.html b/01-introduction.html index 82ad769..da3d340 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -97,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/02-getting-php.html b/02-getting-php.html index c28b616..e107de9 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -95,7 +96,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/03-hello-world.html b/03-hello-world.html index 8bdafba..379d247 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -87,7 +88,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/04-http.html b/04-http.html index 98c3f7a..71379c1 100644 --- a/04-http.html +++ b/04-http.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -78,7 +79,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/05-variables.html b/05-variables.html index 673dace..076640e 100644 --- a/05-variables.html +++ b/05-variables.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -141,7 +142,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/06-functions.html b/06-functions.html index c91ab42..b79a952 100644 --- a/06-functions.html +++ b/06-functions.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -98,7 +99,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/07-classes-1.html b/07-classes-1.html index 748199b..86163b8 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -165,7 +166,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/08-classes-2.html b/08-classes-2.html index 73bb7a5..9017411 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -155,7 +156,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/09-classes-3.html b/09-classes-3.html index 0c208be..ce71e8f 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -165,7 +166,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/10-testing.html b/10-testing.html index b804dab..5992dd7 100644 --- a/10-testing.html +++ b/10-testing.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -172,7 +173,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/11-databases.html b/11-databases.html index 8f4b958..c0a525c 100644 --- a/11-databases.html +++ b/11-databases.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -207,7 +208,7 @@

    Querying the database

    new PDO("sqlite:". __DIR__ . '/database.sqlite') ); -$planet = $planetStore->getPlanet($_GET['name']); +$planet = $planetStore->getPlanet((string)$_GET['name']); header('Content-Type: text/plain'); if ($planet === null) { @@ -243,7 +244,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/12-templating.html b/12-templating.html index ca4c929..bedd5bd 100644 --- a/12-templating.html +++ b/12-templating.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -92,7 +93,7 @@

    Twig

    $templateLoader = new FilesystemLoader(__DIR__ . '/templates/'); $twig = new \Twig\Environment($templateLoader); -$planet = $planetStore->getPlanet($_GET['name']); +$planet = $planetStore->getPlanet((string)$_GET['name']); header('Content-Type: text/html'); if ($planet === null) { @@ -135,7 +136,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/13-static-analysis.html b/13-static-analysis.html new file mode 100644 index 0000000..de6209b --- /dev/null +++ b/13-static-analysis.html @@ -0,0 +1,142 @@ + + + + + + + A Moderately Short PHP Tutorial + + + + + + + + + + + + +
    +
    DRAFT
    +

    A Moderately Short PHP Tutorial

    + +
    +

    Static Analysis

    +

    I recommend using at least one static analysis tool on any PHP project. While languages like TypeScript and Java have +explicit compilation phases that can quickly catch lots of errors, PHP doesn't. Most of the type checks in PHP happen only +as each line of code is executed.

    +

    Unit tests help, but 100% test coverage is unlikely, and even then we can only ever test with a few example inputs. For +more confidence we need static analysis as well, especially if we want to be able to easily refactor our code and upgrade +the libraries we're using.

    +

    Static Analysers for PHP include Psalm, PHPStan and +Phan. In this tutorial we will use Psalm.

    +

    Running Psalm

    +

    Install Psalm with Composer:

    +
    composer require --dev vimeo/psalm
    +

    Create a Psalm Config file:

    +
    ./vendor/bin/psalm --init
    +

    Finally, run Psalm to check your code:

    +
    ./vendor/bin/psalm
    +

    You should see something like:

    +
    Calculating best config level based on project files
    +Calculating best config level based on project files
    +Scanning files...
    +Analyzing files...
    +
    +░E
    +
    +Detected level 7 as a suitable initial default
    +Config file created successfully. Please re-run psalm.
    +

    Re-run Psalm as instructed. If your code is the same as mine, you should see "No errors found!", and +"1 other issues found. You can display them with --show-info=true".

    +

    That's OK, but where's the fun in a static analysis tool that doesn't complain about anything? Let's change the Psalm +settings to make it a lot stricter. Open 'psalm.xml' and change errorLevel="7" to errorLevel="1".

    +

    Re-run Psalm. Now you should see an error:

    +

    +ERROR: InvalidArgument - src/PlanetStore.php:52:27 - Argument 1 of AModeratelyShortPhpTutorial\Planet::__construct expects string, scalar provided
    +        return new Planet($row['name'], (float)$row['population_size']); +

    +

    Psalm has looked at our code, and the code of the libraries and modules we're using, and found a mismatch. The planet +class constructor needs a string, but we've passed it something from the array returned by the +PDOStatement::fetch. Psalm knows that when we call fetch with +the \PDO::FETCH_ASSOC we will either get false or an array of scalar values (i.e. not objects). It can see that the +value isn't false at line 52, because when it is false the function returns early, skipping that line.

    +

    In this case we know our database a bit better than Psalm does, and we need to add a comment to tell Psalm that fetch +will return either false or an array of strings. Edit 'PlanetStore.php' and add docblock for the $row variable:

    +
            /** @var array<string, string>|false $row */
    +        $row = $statement->fetch(PDO::FETCH_ASSOC);
    +

    This docbloc means that the $row variable's type is the union of false and string-indexed, string-valued array. In +other words it either holds the value false, or it holds an array, in which any keys are strings and any values are +also strings. | combines types to make a union type. The < > brackets are used to provide arguments for a +generic type. false is an example of a literal type.

    +

    Psalm's type system extends the PHP type system, and is a lot more expressive. PHP itself does not have union, generic, +or literal types, although unions are coming in PHP 8. We can use types that PHP doesn't support by writing them in +docblocks, with tags such as +@var, +@param, and +@return, +and making sure we run our static analysis tool every time +we edit our source code.

    +

    Let's add a deliberate mistake to our code to see a bit more of what Psalm can help us with. Let's suppose we forgot +that the database might not have the planet we're looking for. Comment out the check for that in 'planetStore.php':

    +
    //        if (! $row) {
    +//            return null;
    +//        }
    +

    Re-run Psalm. It now reports two PossiblyInvalidArrayAccess errors, telling us that we +'Cannot access array value on non-array variable $row of type false'. This is a reminder that we should have made sure +that $row is not false before trying to use it as an array. If we leave it like this our server will produce an HTTP +500 internal server error instead of displaying the 404 page when someone asks to see the planet Pluto. Put the check +back to make Psalm happy again.

    +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/14-further-reading.html b/14-further-reading.html index e34b3d2..dcaac57 100644 --- a/14-further-reading.html +++ b/14-further-reading.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -67,7 +68,7 @@

    A Moderately Short PHP Tutorial

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    diff --git a/index.html b/index.html index 82ad769..da3d340 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,7 @@

    A Moderately Short PHP Tutorial

  • 10-testing
  • 11-databases
  • 12-templating
  • +
  • 13-static-analysis
  • 14-further-reading
  • @@ -97,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 20:43.

    +

    Site built Sat, 29 Feb 2020 22:28.

    From 60f0e884a032afad349bf3a2007a8799bb8ff96b Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 23:47:16 +0000 Subject: [PATCH 20/40] Update GH Pages based on CircleCI Build 117 [ci skip] --- 01-introduction.html | 4 +- 02-getting-php.html | 4 +- 03-hello-world.html | 4 +- 04-http.html | 4 +- 05-variables.html | 4 +- 06-functions.html | 4 +- 07-classes-1.html | 4 +- 08-classes-2.html | 4 +- 09-classes-3.html | 4 +- 10-testing.html | 4 +- 11-databases.html | 4 +- 12-templating.html | 4 +- 13-static-analysis.html | 11 +-- 14-further-reading.html | 77 --------------------- 14-what-next.html | 147 ++++++++++++++++++++++++++++++++++++++++ index.html | 4 +- 16 files changed, 179 insertions(+), 108 deletions(-) delete mode 100644 14-further-reading.html create mode 100644 14-what-next.html diff --git a/01-introduction.html b/01-introduction.html index da3d340..0a0c2d8 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -98,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/02-getting-php.html b/02-getting-php.html index e107de9..58fc79b 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -96,7 +96,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/03-hello-world.html b/03-hello-world.html index 379d247..a4d1ba8 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -88,7 +88,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/04-http.html b/04-http.html index 71379c1..8664124 100644 --- a/04-http.html +++ b/04-http.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -79,7 +79,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/05-variables.html b/05-variables.html index 076640e..e478542 100644 --- a/05-variables.html +++ b/05-variables.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -142,7 +142,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/06-functions.html b/06-functions.html index b79a952..f1354a6 100644 --- a/06-functions.html +++ b/06-functions.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -99,7 +99,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/07-classes-1.html b/07-classes-1.html index 86163b8..7b73294 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -166,7 +166,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/08-classes-2.html b/08-classes-2.html index 9017411..31beb47 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -156,7 +156,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/09-classes-3.html b/09-classes-3.html index ce71e8f..f13399a 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -166,7 +166,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/10-testing.html b/10-testing.html index 5992dd7..4d13baf 100644 --- a/10-testing.html +++ b/10-testing.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -173,7 +173,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/11-databases.html b/11-databases.html index c0a525c..9fe6e8a 100644 --- a/11-databases.html +++ b/11-databases.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -244,7 +244,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/12-templating.html b/12-templating.html index bedd5bd..f856e67 100644 --- a/12-templating.html +++ b/12-templating.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -136,7 +136,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/13-static-analysis.html b/13-static-analysis.html index de6209b..44fe86b 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -89,9 +89,10 @@

    Running Psalm

    Psalm has looked at our code, and the code of the libraries and modules we're using, and found a mismatch. The planet class constructor needs a string, but we've passed it something from the array returned by the -PDOStatement::fetch. Psalm knows that when we call fetch with -the \PDO::FETCH_ASSOC we will either get false or an array of scalar values (i.e. not objects). It can see that the -value isn't false at line 52, because when it is false the function returns early, skipping that line.

    +PDOStatement::fetch.

    +

    Psalm knows that when we call fetch with \PDO::FETCH_ASSOC we will either get false or an array of scalar +values (i.e. not objects). It can see that the value isn't false at line 52, because when it is false the function +returns early, skipping that line.

    In this case we know our database a bit better than Psalm does, and we need to add a comment to tell Psalm that fetch will return either false or an array of strings. Edit 'PlanetStore.php' and add docblock for the $row variable:

            /** @var array<string, string>|false $row */
    @@ -133,7 +134,7 @@ 

    Running Psalm

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    diff --git a/14-further-reading.html b/14-further-reading.html deleted file mode 100644 index dcaac57..0000000 --- a/14-further-reading.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - A Moderately Short PHP Tutorial - - - - - - - - - - - - -
    -
    DRAFT
    -

    A Moderately Short PHP Tutorial

    - -
    - -
    - -
    - Copyright Barney Laurance 2020 -
    - - - -
    - - \ No newline at end of file diff --git a/14-what-next.html b/14-what-next.html new file mode 100644 index 0000000..10838da --- /dev/null +++ b/14-what-next.html @@ -0,0 +1,147 @@ + + + + + + + A Moderately Short PHP Tutorial + + + + + + + + + + + + +
    +
    DRAFT
    +

    A Moderately Short PHP Tutorial

    + +
    +

    What next?

    +

    This has only been a cursory introduction to the PHP language and ecosystem. Here are some ideas for things to try next, +in no particular order:

    + +
    + +
    + Copyright Barney Laurance 2020 +
    + + + +
    + + \ No newline at end of file diff --git a/index.html b/index.html index da3d340..0a0c2d8 100644 --- a/index.html +++ b/index.html @@ -48,7 +48,7 @@

    A Moderately Short PHP Tutorial

  • 11-databases
  • 12-templating
  • 13-static-analysis
  • -
  • 14-further-reading
  • +
  • 14-what-next
  • @@ -98,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 22:28.

    +

    Site built Sat, 29 Feb 2020 23:47.

    From e26c1d5a8135c973627a44060afc4bf1431fde84 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 29 Feb 2020 23:51:00 +0000 Subject: [PATCH 21/40] Update GH Pages based on CircleCI Build 120 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- 13-static-analysis.html | 2 +- 14-what-next.html | 5 +++-- index.html | 2 +- 15 files changed, 17 insertions(+), 16 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 0a0c2d8..9ba5373 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -98,7 +98,7 @@

    Why did I write it?

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/02-getting-php.html b/02-getting-php.html index 58fc79b..0c5fb38 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -96,7 +96,7 @@

    Windows

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/03-hello-world.html b/03-hello-world.html index a4d1ba8..1dc125a 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -88,7 +88,7 @@

    Hello, world.

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/04-http.html b/04-http.html index 8664124..7a3d410 100644 --- a/04-http.html +++ b/04-http.html @@ -79,7 +79,7 @@

    HTTP

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/05-variables.html b/05-variables.html index e478542..8ed93b5 100644 --- a/05-variables.html +++ b/05-variables.html @@ -142,7 +142,7 @@

    Associative arrays

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/06-functions.html b/06-functions.html index f1354a6..3dea584 100644 --- a/06-functions.html +++ b/06-functions.html @@ -99,7 +99,7 @@

    Functions

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/07-classes-1.html b/07-classes-1.html index 7b73294..8c5a0d1 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -166,7 +166,7 @@

    What's in the class

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/08-classes-2.html b/08-classes-2.html index 31beb47..77b61f3 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -156,7 +156,7 @@

    Composer

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/09-classes-3.html b/09-classes-3.html index f13399a..880647b 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -166,7 +166,7 @@

    Object Identity

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/10-testing.html b/10-testing.html index 4d13baf..7ef316a 100644 --- a/10-testing.html +++ b/10-testing.html @@ -173,7 +173,7 @@

    Writing a test

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/11-databases.html b/11-databases.html index 9fe6e8a..66fbc8b 100644 --- a/11-databases.html +++ b/11-databases.html @@ -244,7 +244,7 @@

    Other Database Engines.

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/12-templating.html b/12-templating.html index f856e67..ec6fb04 100644 --- a/12-templating.html +++ b/12-templating.html @@ -136,7 +136,7 @@

    Twig

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/13-static-analysis.html b/13-static-analysis.html index 44fe86b..d843f89 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -134,7 +134,7 @@

    Running Psalm

    -

    Site built Sat, 29 Feb 2020 23:47.

    +

    Site built Sat, 29 Feb 2020 23:50.

    diff --git a/14-what-next.html b/14-what-next.html index 10838da..4ed0d44 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -58,7 +58,8 @@

    What next?

    • If you enjoyed this tutorial, or found it useful please let me know and share it. If you think it could be improved, -let me know that too. You can find me on twitter.

      +let me know that too. You can find me on twitter. You can also find +the source code of this website on GitHub.

    • Take a break from the screen - there's good evidence that you remember more of what you've learned shortly before or @@ -138,7 +139,7 @@

      What next?

      -

      Site built Sat, 29 Feb 2020 23:47.

      +

      Site built Sat, 29 Feb 2020 23:50.

      diff --git a/index.html b/index.html index 0a0c2d8..9ba5373 100644 --- a/index.html +++ b/index.html @@ -98,7 +98,7 @@

      Why did I write it?

      -

      Site built Sat, 29 Feb 2020 23:47.

      +

      Site built Sat, 29 Feb 2020 23:50.

      From 0492b0dbd385f12bec0ccefc1023f8d4329fd323 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 1 Mar 2020 00:12:01 +0000 Subject: [PATCH 22/40] Update GH Pages based on CircleCI Build 123 [ci skip] --- 01-introduction.html | 18 ++++-------------- 02-getting-php.html | 18 ++++-------------- 03-hello-world.html | 18 ++++-------------- 04-http.html | 18 ++++-------------- 05-variables.html | 18 ++++-------------- 06-functions.html | 18 ++++-------------- 07-classes-1.html | 18 ++++-------------- 08-classes-2.html | 18 ++++-------------- 09-classes-3.html | 18 ++++-------------- 10-testing.html | 18 ++++-------------- 11-databases.html | 18 ++++-------------- 12-templating.html | 18 ++++-------------- 13-static-analysis.html | 18 ++++-------------- 14-what-next.html | 18 ++++-------------- css/styles.css | 15 +++------------ index.html | 18 ++++-------------- 16 files changed, 63 insertions(+), 222 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 9ba5373..d31fa07 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
      -
      DRAFT

      A Moderately Short PHP Tutorial

        @@ -86,21 +84,13 @@

        Why did I write it?

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/02-getting-php.html b/02-getting-php.html index 0c5fb38..8d89402 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -84,21 +82,13 @@

      Windows

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/03-hello-world.html b/03-hello-world.html index 1dc125a..37452c1 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -76,21 +74,13 @@

      Hello, world.

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/04-http.html b/04-http.html index 7a3d410..cfc4633 100644 --- a/04-http.html +++ b/04-http.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -67,21 +65,13 @@

      HTTP

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/05-variables.html b/05-variables.html index 8ed93b5..3dd1bb4 100644 --- a/05-variables.html +++ b/05-variables.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -130,21 +128,13 @@

      Associative arrays

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/06-functions.html b/06-functions.html index 3dea584..d3cad5f 100644 --- a/06-functions.html +++ b/06-functions.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -87,21 +85,13 @@

      Functions

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/07-classes-1.html b/07-classes-1.html index 8c5a0d1..9a7595b 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -154,21 +152,13 @@

      What's in the class

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/08-classes-2.html b/08-classes-2.html index 77b61f3..45c6b40 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -144,21 +142,13 @@

      Composer

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/09-classes-3.html b/09-classes-3.html index 880647b..f273748 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -154,21 +152,13 @@

      Object Identity

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/10-testing.html b/10-testing.html index 7ef316a..c128ef4 100644 --- a/10-testing.html +++ b/10-testing.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -161,21 +159,13 @@

      Writing a test

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/11-databases.html b/11-databases.html index 66fbc8b..93f853f 100644 --- a/11-databases.html +++ b/11-databases.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -232,21 +230,13 @@

      Other Database Engines.

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/12-templating.html b/12-templating.html index ec6fb04..7465b59 100644 --- a/12-templating.html +++ b/12-templating.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -124,21 +122,13 @@

      Twig

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/13-static-analysis.html b/13-static-analysis.html index d843f89..8ae7b1e 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -122,21 +120,13 @@

      Running Psalm

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/14-what-next.html b/14-what-next.html index 4ed0d44..891614d 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -127,21 +125,13 @@

      What next?

    - Copyright Barney Laurance 2020 -
    - - + diff --git a/css/styles.css b/css/styles.css index 2642b6b..f96e81a 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,10 +1,12 @@ #pages ul { display:flex; + flex-wrap: wrap; list-style:none; } #pages ul li { - margin: 1em; + margin: 0.2em 1em; + min-width: 10em; } body > div { @@ -16,17 +18,6 @@ body > div { text-align: right; } -#draft { - position: absolute; - top: 1.5em; - transform-origin: center; - transform: rotate(45deg); - font-size: 15em; - pointer-events: none; - font-weight: bolder; - color: rgba(0,0,0,0.07); -} - #footer { margin-top: 1em; padding: 1em; diff --git a/index.html b/index.html index 9ba5373..d31fa07 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,6 @@ - A Moderately Short PHP Tutorial @@ -31,7 +30,6 @@
    -
    DRAFT

    A Moderately Short PHP Tutorial

      @@ -86,21 +84,13 @@

      Why did I write it?

    - Copyright Barney Laurance 2020 -
    - - + From aab93d68dd98daff67a9f6ea8d096e9e28f2a7a4 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 1 Mar 2020 02:03:14 +0000 Subject: [PATCH 23/40] Update GH Pages based on CircleCI Build 128 [ci skip] --- 01-introduction.html | 130 +++++++++++++++++++++++++--------------- 02-getting-php.html | 99 ++++++++++++++++++++++-------- 03-hello-world.html | 97 ++++++++++++++++++++++-------- 04-http.html | 97 ++++++++++++++++++++++-------- 05-variables.html | 101 +++++++++++++++++++++++-------- 06-functions.html | 97 ++++++++++++++++++++++-------- 07-classes-1.html | 103 ++++++++++++++++++++++--------- 08-classes-2.html | 99 ++++++++++++++++++++++-------- 09-classes-3.html | 99 ++++++++++++++++++++++-------- 10-testing.html | 101 +++++++++++++++++++++++-------- 11-databases.html | 105 +++++++++++++++++++++++--------- 12-templating.html | 103 ++++++++++++++++++++++--------- 13-static-analysis.html | 99 ++++++++++++++++++++++-------- 14-what-next.html | 96 +++++++++++++++++++++-------- css/styles.css | 57 ++++++++++++++++-- index.html | 130 +++++++++++++++++++++++++--------------- 16 files changed, 1184 insertions(+), 429 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index d31fa07..fbf873b 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Introduction | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Who is this for?

    -

    This is for anyone who wants to learn to program in PHP as a second language.

    -

    You should already know at least one programming language with curly braces, if conditions, variables, functions and +

    Introduction

    +

    Who is this for?

    +

    This is for anyone who wants to learn to program in PHP.

    +

    You should probably already know at least one programming language with curly braces, if conditions, variables, functions and loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and Typescript.

    -

    Why did I write it?

    -

    (This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

    +

    Why did I write it?

    I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory -tutorial to recommend they can work through, but I didn't find anything satisfying.

    -

    The tutorial at php.net appears not to have been updated for several years, -and doesn't even introduce the function or class keywords. On the other hand it does show PHP mixed with HTML, -which I plan to pretend doesn't exist. I think it's now probably worse than useless.

    -

    David Brumbaugh's -Learn a New Language: Migrating from JavaScript to PHP -is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what Composer is, -and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to -require the reader to install at least PHP 7.2, and spend little if any time on older versions.

    -

    PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good -advice, but it's not really a tutorial to work through step by step. I think it could be overwhelming as an introduction -to PHP, and covers a lot more than I think most new PHP developers would want to know, including several paragraphs about -the MySQL Extension, which as it says "is incredibly old and has been superseded by two other extensions". I plan to -concentrate on the parts of PHP that I can recommend.

    -

    For PHP devs learning some Javascript, typescript, and/or React there seem to be great materials available online, -such as the React Tutorial, -HTML Dog's Javascript Tutorials, -TypeScript in 5 minutes and the (paid) Typescript course at -Execute Program. As far as I can tell there's nothing similar available free to help -JS devs learn some PHP.

    +tutorial to recommend they can work through, but I didn't find anything that seemed exactly right.

    +

    Approach

    +

    This is a step-by-step guide to using a selection of the most important aspects of PHP. It doesn't attempt to be +comprehensive.

    +

    PHP is an old language that has evolved organically over the years. There are many ways to do things, +and many parts of the language that are best avoided in new code. This tutorial will concentrate on recommended +ways to use PHP, and ignore most of the things that PHP allows you to do but you probably shouldn't.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/02-getting-php.html b/02-getting-php.html index 8d89402..116e367 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Getting PHP | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Getting PHP

    -

    If you just want to run a PHP one-liner, or experiment with a tiny throwaway PHP script, the easiest way is probably +

    Getting PHP

    +

    If you just want to run a PHP one-liner, or experiment with a tiny throwaway PHP script, the easiest way is probably online at 3v4l, but to work through this tutorial you should have PHP installed on your computer.

    -

    Installation

    +

    Installation

    First check if you already have PHP installed. Open your command-line prompt, and type php --v. If you have PHP, you should see something like:

    PHP 7.4.2 (cli) (built: Jan 23 2020 11:21:30) ( NTS )
    @@ -81,12 +113,29 @@ 

    Windows

    Run php -v again. Hopefully you will now have version 7.2 or later.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/03-hello-world.html b/03-hello-world.html index 37452c1..21c9ed4 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Hello, world | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Hello, world.

    -

    At this point we're ready to start writing in PHP. Make a new folder for your PHP code.

    +

    Hello, world

    +

    At this point we're ready to start writing in PHP. Make a new folder for your PHP code.

    If you have a favourite text editor or integrated development environment, such as Vim, Atom, or VS Code you may want to stick with that, but the best tool for editing PHP code is almost certainly JetBrains' PhpStorm. PhpStorm is free for 30 days, but will demand money after that.

    @@ -73,12 +105,29 @@

    Hello, world.

    20% shorter to write.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/04-http.html b/04-http.html index cfc4633..4d6184a 100644 --- a/04-http.html +++ b/04-http.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + HTTP | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    HTTP

    -

    PHP is of course mostly used in web servers, so you might be wondering why we started with a command line script.

    +

    HTTP

    +

    PHP is of course mostly used in web servers, so you might be wondering why we started with a command line script.

    In fact you can access the same script through your web browser. PHP comes with a built-in web server for development and testing uses. To start it, run:

    php -S localhost:8080
    @@ -64,12 +96,29 @@

    HTTP

    Wordpress or Drupal.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/05-variables.html b/05-variables.html index 3dd1bb4..e19e4a1 100644 --- a/05-variables.html +++ b/05-variables.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Variables, arrays and loops | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Variables, arrays and loops

    -

    Variables in PHP always have a dollar sign $ at the start of their names, and you declare a variable by assigning a +

    Variables, arrays and loops

    +

    Variables in PHP always have a dollar sign $ at the start of their names, and you declare a variable by assigning a value to it. PHP interpolates double-quoted strings with variables. Edit hello.php to use a variable:

    <?php declare(strict_types=1);
     
    @@ -60,7 +92,7 @@ 

    Variables, arrays and loops

    echo "Hello, $planet.\n";

    You can probably guess what this will do when you run it on your command line or serve it to your browser.

    -

    Arrays and loops

    +

    Arrays and loops

    PHP has a very versatile built-in type called array. You're unlikely to find much PHP code that doesn't use arrays extensively, but they are easy to overuse at the cost of other more expressive types. Despite the name, a PHP array isn't really an array as you may know it from other languages. A PHP array is an ordered iterable map, with keys @@ -108,7 +140,7 @@

    Arrays and loops

    Re-run the script - the planets are now listed in reverse order. But notice that the array keys have not changed - Mercury is still planet number 0, it's just that 0 now comes last. PHP array keys can come in any order.

    -

    Associative arrays

    +

    Associative arrays

    We can also assign array keys explicitly. When we're interested in the keys of an array we call it an associative array. For example:

    <?php declare(strict_types=1);
    @@ -127,12 +159,29 @@ 

    Associative arrays

    echo "The population of Earth is {$planetPopulations['Earth']}.\n";
    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/06-functions.html b/06-functions.html index d3cad5f..40363cb 100644 --- a/06-functions.html +++ b/06-functions.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Functions | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Functions

    -

    PHP comes with hundreds of built in functions, to sort arrays, find the +

    Functions

    +

    PHP comes with hundreds of built in functions, to sort arrays, find the length of strings, match regexes, or even get the timestamp corresponding to midnight on Easter of a given year, but you will inevitably want to define your own functions. Function definitions look like this:

    @@ -84,12 +116,29 @@

    Functions

    the function that would also be a fatal error.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/07-classes-1.html b/07-classes-1.html index 9a7595b..64ab628 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Classes and Objects | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Classes and Objects

    -

    PHP supports class-based object oriented programming, heavily influenced by Java and similar languages. This is +

    Classes and Objects

    +

    PHP supports class-based object oriented programming, heavily influenced by Java and similar languages. This is different to the prototype based OO in JavaScript.

    In the sort of PHP code I write almost 100% of the code in a project is in classes - some classes are used to make objects, and others may just be convenient wrappers around groups of functions.

    @@ -84,7 +116,7 @@

    Classes and Objects

    return $this->populationSize; } } -

    Older PHP Versions

    +

    Older PHP Versions

    name and populationSize are the properties of the class, and they have string and float types respectively. Before 7.4 PHP didn't allow us to specify types for properties. We still want to know what types of values we intend to put in the properties, so we use a DocBlock instead. If you don't have 7.4 yet, change the property declarations @@ -101,10 +133,10 @@

    Older PHP Versions

    These DocBlocks are ignored by the PHP engine, but they are very useful for us, and many tools and IDEs will read them. The code inside the docblock is written in the PHPDoc language.

    -

    Running the code

    +

    Running the code

    Run php Planet.php. You should see no output - a class by itself doesn't do anything. We will write code to use this class on the next page.

    -

    What's in the class

    +

    What's in the class

    Let's read through the class from top to bottom.

    • @@ -151,12 +183,29 @@

      What's in the class

      JavaScript module that exports some but not all of its symbols.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/08-classes-2.html b/08-classes-2.html index 45c6b40..55cfe2c 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Classes and Composer | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Classes Part 2

    -

    On the last page we wrote Planet class, and saved it in a file called Planet.php. Now we want to put that class +

    Classes and Composer

    +

    On the last page we wrote Planet class, and saved it in a file called Planet.php. Now we want to put that class to work.

    PHP works by executing whatever script we give it from beginning to end. It won't run anything inside a class unless we that script tells it to, so every PHP program needs at least one line that isn't part of any class as an entry-point. @@ -71,7 +103,7 @@

    Classes Part 2

    The new keyword creates objects instances from classes, and automatically calls any constructor the class has.

    We can try running this now but it won't work just yet, because we need to link it up with Planet.php. When you type php start.php you should see PHP Fatal error: Uncaught Error: Class 'Planet' not found.

    -

    Linking files together

    +

    Linking files together

    There are two main ways to link files together. The old way is require_once, and the new ways is composer. We'll start with require_once.

    Require_once

    @@ -141,12 +173,29 @@

    Composer

    If you run php start.php you should once again learn the population of Neptune.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/09-classes-3.html b/09-classes-3.html index f273748..2984d62 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Classes, Static Methods, and Object Identity | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Classes Part 3

    -

    Static methods

    +

    Classes, Static Methods, and Object Identity

    +

    Static methods

    Not all the methods on a class have to run in the context of an object. Methods that work without a $this object instance are called static methods. Let's add a static method to the Planet class in src/Planet.php:

    <?php declare(strict_types=1);
    @@ -102,7 +134,7 @@ 

    Static methods

    echo "Planet {$planet->getName()} has a population of {$planet->getPopulationSize()}.\n";

    The double colon is the Scope Resolution Operator. It accesses static methods (and properties) of classes - there is no need to have an object first. In this case our method returns an instance of the class, but it could do anything.

    -

    Object Identity

    +

    Object Identity

    A PHP variable can't actually hold an object - instead it holds an object identifier, also known as a reference.

    Two objects created the same way, with the same properties will have distinct identities. But if one object is created and then assigned to two variables, they will both hold identifiers for the same object. This becomes important when we @@ -151,12 +183,29 @@

    Object Identity

    confusing if not managed carefully.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/10-testing.html b/10-testing.html index c128ef4..7381fcb 100644 --- a/10-testing.html +++ b/10-testing.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Testing | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Testing

    -

    If we want to work on even a moderately complex program over time, we need automated testing - manually testing +

    Testing

    +

    If we want to work on even a moderately complex program over time, we need automated testing - manually testing everything every time we make a change would quickly become unsustainable.

    -

    Installing PHPUnit

    +

    Installing PHPUnit

    The leading test framework for PHP is Sebastian Bergmann's PHPUnit.

    Since we already have composer set up for our project, we can use that to install PHPUnit in the vendor directory. Run:

    composer require --dev phpunit/phpunit
    @@ -81,7 +113,7 @@

    Installing PHPUnit

    installed. At the time of writing it shows me that PHPUnit is at version 9.0.1, and I can see the details of 29 other packages that have been installed because PHPUnit depends on them directly or indirectly. The composer show command will output the list of installed packages in a much more consice format.

    -

    Writing a test

    +

    Writing a test

    Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

    <?php declare(strict_types=1);
     
    @@ -158,12 +190,29 @@ 

    Writing a test

    and be readable by people who haven't been trained in programming.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/11-databases.html b/11-databases.html index 93f853f..0934d2f 100644 --- a/11-databases.html +++ b/11-databases.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Databases | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Databases

    -

    PHP applications often connect to databases. This is even harder to avoid in PHP than it would be in other languages +

    Databases

    +

    PHP applications often connect to databases. This is even harder to avoid in PHP than it would be in other languages you can run on a web server like JS, Java, or C#, because PHP has a shared-nothing architecture. That means that the code dealing with each request runs in isolation, and does not share any objects or variables with other requests. At the end of the request-response cycle all stack frames are unwound and all objects become garbage.

    @@ -62,7 +94,7 @@

    Databases

    The details of SQL, the programming language for defining and querying databases, are beyond the scope of this tutorial. We will see some SQL code, but as far as PHP is concerned they are just strings to send to the database engine.

    -

    Install the SQLite PHP Module

    +

    Install the SQLite PHP Module

    We will use our SQLite database via PHP's PHP Data Objects (PDO) extension, which provides a consistent interface for accessing many different DB types.

    First check if the necessary PHP modules are installed. Run php -i | grep sqlite. If you have the module set up, @@ -79,7 +111,7 @@

    Mac

    If you installed PHP via homebrew, I think will automatically have come with SQLite built in and enabled.

    Windows

    If you installed PHP as part of XAMPP this should have SQLite enabled by default.

    -

    Creating a database

    +

    Creating a database

    First, let's write a PHP script src/create-database.php to create a new database with one table:

    <?php declare(strict_types=1);
     
    @@ -109,7 +141,7 @@ 

    Creating a database

    PDO constructor we pass it a string holding details of the database we want to connect to, known as a Data Source Name or DSN. For SQLite the DSN consists of 'sqlite:' followed by an absolute file path.

    -

    Querying the database

    +

    Querying the database

    Let's write a very small program to put the planets in the database, and let us view info about any planet. First we will need a class that can insert all the planets. Make a file src/PlanetStore.php

    <?php declare(strict_types=1);
    @@ -223,18 +255,35 @@ 

    Querying the database

    Run the PHP server:

    php -S localhost:8080

    Open http://localhost:8080/viewPlanet.php?name=Earth in your browser.

    -

    Other Database Engines.

    +

    Other Database Engines.

    PDO has drivers for eleven other database engines that you can use use instead of SQLite. Connecting, sending queries, and receiving rows should work in the same way, but of course the details of connection strings and SQL code will vary from DB to DB.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/12-templating.html b/12-templating.html index 7465b59..d6251aa 100644 --- a/12-templating.html +++ b/12-templating.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Templating | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Templating

    -

    Our planet viewer works, but it isn't pretty. Let's use some HTML to make it look a little better.

    +

    Templating

    +

    Our planet viewer works, but it isn't pretty. Let's use some HTML to make it look a little better.

    It has been a common practice to use PHP as a templating language, and even mix PHP and HTML code together in the same file. While PHP can still be used as a templating language, it isn't a good one, so we won't do that.

    Instead, we will use PHP to prepare whatever data we want to show, and then pass that to a template written in a different language.

    There are dozens of template engines available as libraries to use in PHP programs, and another good option is to make a single page application, with all templating done in the browser, and data sent from the server as JSON.

    -

    Twig

    +

    Twig

    For this tutorial we will write a template in the Twig language, which works with PHP.

    First install Twig in your project by running:

    composer require "twig/twig:^3.0"
    @@ -112,21 +144,38 @@

    Twig

    Finally we need to edit 'planet.html.twig'. Since we won't always be reading the template at the same time as the PHP file that uses it, and neither will any tools and IDEs we might be using, we should add a comment to make it clear that we expect to have a planet variable, and it will be of type Planet. Add the following to the top of the file:

    -
    {#  @var planet AModeratelyShortPhpTutorial\Planet #}
    +

    In Twig we use double curly brackets to output dynamic data: Replace Some Planet with -{{planet.name}}, and replace 34601 with {{planet.populationSize}}. Twig knows that we mean getName and +, and replace `34601` with. Twig knows that we mean getName and getPopulationSize, so we don't have to write those function names out in full.

    If you reload the page you should now see the planet details in their proper places.

    Twig is a full featured special purpose programming language, with features like loops, conditionals, filters, inheritance, etc, but this is a PHP tutorial, not a Twig tutorial.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/13-static-analysis.html b/13-static-analysis.html index 8ae7b1e..0a2a415 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Static Analysis | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Static Analysis

    -

    I recommend using at least one static analysis tool on any PHP project. While languages like TypeScript and Java have +

    Static Analysis

    +

    I recommend using at least one static analysis tool on any PHP project. While languages like TypeScript and Java have explicit compilation phases that can quickly catch lots of errors, PHP doesn't. Most of the type checks in PHP happen only as each line of code is executed.

    Unit tests help, but 100% test coverage is unlikely, and even then we can only ever test with a few example inputs. For @@ -59,7 +91,7 @@

    Static Analysis

    the libraries we're using.

    Static Analysers for PHP include Psalm, PHPStan and Phan. In this tutorial we will use Psalm.

    -

    Running Psalm

    +

    Running Psalm

    Install Psalm with Composer:

    composer require --dev vimeo/psalm

    Create a Psalm Config file:

    @@ -119,12 +151,29 @@

    Running Psalm

    back to make Psalm happy again.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/14-what-next.html b/14-what-next.html index 891614d..6fc32df 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + What next? | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    What next?

    -

    This has only been a cursory introduction to the PHP language and ecosystem. Here are some ideas for things to try next, +

    What next?

    +

    This has only been a cursory introduction to the PHP language and ecosystem. Here are some ideas for things to try next, in no particular order:

    • @@ -124,12 +156,28 @@

      What next?

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + diff --git a/css/styles.css b/css/styles.css index f96e81a..667c501 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,12 +1,34 @@ #pages ul { - display:flex; - flex-wrap: wrap; - list-style:none; + display: flex; + align-items: start; + justify-content: center; + flex-flow: column wrap; + align-content: stretch; + max-height: 13em; +} + +@media (max-width: 1000px) { + #pages ul { + max-height: none; + } } #pages ul li { margin: 0.2em 1em; - min-width: 10em; + min-width: 20em; + display: block; + flex: 1 1 0; + border-bottom: 0.1em rgba(0,0,0,0) solid; + padding-bottom: 0.1em; +} + +#pages ul li.current { + list-style: disc; + border-bottom-color: black; +} + +#pages ul li.current a { + color: inherit; } body > div { @@ -18,9 +40,34 @@ body > div { text-align: right; } +#previous { + width: 50%; + float: left; + text-align: left; +} + +#next { + width: 50%; + float: left; + text-align: right; +} + #footer { margin-top: 1em; padding: 1em; border: 2px solid #b0b0b0; background-color: #dcdcdc; -} \ No newline at end of file +} + +a { + text-decoration: inherit; +} + +a:hover, a:focus { + text-decoration: underline; +} + +h1 a { + text-decoration: inherit; + color: inherit; +} diff --git a/index.html b/index.html index d31fa07..fbf873b 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - A Moderately Short PHP Tutorial + Introduction | A Moderately Short PHP Tutorial
    -

    A Moderately Short PHP Tutorial

    +

    + A Moderately Short PHP Tutorial + +

    +
    -

    Who is this for?

    -

    This is for anyone who wants to learn to program in PHP as a second language.

    -

    You should already know at least one programming language with curly braces, if conditions, variables, functions and +

    Introduction

    +

    Who is this for?

    +

    This is for anyone who wants to learn to program in PHP.

    +

    You should probably already know at least one programming language with curly braces, if conditions, variables, functions and loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and Typescript.

    -

    Why did I write it?

    -

    (This part should probably be moved out of the intro, perhaps entirely out of the main tutorial content.)

    +

    Why did I write it?

    I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP side of our application, but don't have PHP experience from their previous jobs. I looked around for an introductory -tutorial to recommend they can work through, but I didn't find anything satisfying.

    -

    The tutorial at php.net appears not to have been updated for several years, -and doesn't even introduce the function or class keywords. On the other hand it does show PHP mixed with HTML, -which I plan to pretend doesn't exist. I think it's now probably worse than useless.

    -

    David Brumbaugh's -Learn a New Language: Migrating from JavaScript to PHP -is much closer to what I want to write, but it's a bit too short. It doesn't explain how to install PHP, or what Composer is, -and again it prominently covers mixing PHP with HTML. It shows both the pre-and post 5.4 array syntax, whereas I want to -require the reader to install at least PHP 7.2, and spend little if any time on older versions.

    -

    PHP The Right Way is often recommended to PHP beginners, for good reasons. It has very good -advice, but it's not really a tutorial to work through step by step. I think it could be overwhelming as an introduction -to PHP, and covers a lot more than I think most new PHP developers would want to know, including several paragraphs about -the MySQL Extension, which as it says "is incredibly old and has been superseded by two other extensions". I plan to -concentrate on the parts of PHP that I can recommend.

    -

    For PHP devs learning some Javascript, typescript, and/or React there seem to be great materials available online, -such as the React Tutorial, -HTML Dog's Javascript Tutorials, -TypeScript in 5 minutes and the (paid) Typescript course at -Execute Program. As far as I can tell there's nothing similar available free to help -JS devs learn some PHP.

    +tutorial to recommend they can work through, but I didn't find anything that seemed exactly right.

    +

    Approach

    +

    This is a step-by-step guide to using a selection of the most important aspects of PHP. It doesn't attempt to be +comprehensive.

    +

    PHP is an old language that has evolved organically over the years. There are many ways to do things, +and many parts of the language that are best avoided in new code. This tutorial will concentrate on recommended +ways to use PHP, and ignore most of the things that PHP allows you to do but you probably shouldn't.

    -
    - - Copyright Barney Laurance
    - Site generated from sources at 00:11 London time on - Sun 01 Mar 2020. -
    + + + + + + + + + +
    + + From d0771c027e1828d0e970ffb8a2fd61d201ac6aeb Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 1 Mar 2020 02:06:06 +0000 Subject: [PATCH 24/40] Update GH Pages based on CircleCI Build 131 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- 13-static-analysis.html | 2 +- 14-what-next.html | 2 +- index.html | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index fbf873b..4980f36 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -121,7 +121,7 @@

    Approach

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 116e367..1c78a9f 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -132,7 +132,7 @@

    Windows

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index 21c9ed4..c7d8ea8 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -124,7 +124,7 @@

    Hello, world

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/04-http.html b/04-http.html index 4d6184a..cd7d22c 100644 --- a/04-http.html +++ b/04-http.html @@ -115,7 +115,7 @@

    HTTP

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/05-variables.html b/05-variables.html index e19e4a1..d7eb486 100644 --- a/05-variables.html +++ b/05-variables.html @@ -178,7 +178,7 @@

    Associative arrays

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/06-functions.html b/06-functions.html index 40363cb..28da1d3 100644 --- a/06-functions.html +++ b/06-functions.html @@ -135,7 +135,7 @@

    Functions

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 64ab628..c5bc285 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -202,7 +202,7 @@

    What's in the class

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 55cfe2c..9352d8e 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -192,7 +192,7 @@

    Composer

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 2984d62..ea01db7 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -202,7 +202,7 @@

    Object Identity

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/10-testing.html b/10-testing.html index 7381fcb..129ce3e 100644 --- a/10-testing.html +++ b/10-testing.html @@ -209,7 +209,7 @@

    Writing a test

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/11-databases.html b/11-databases.html index 0934d2f..aafecde 100644 --- a/11-databases.html +++ b/11-databases.html @@ -280,7 +280,7 @@

    Other Database Engines.

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/12-templating.html b/12-templating.html index d6251aa..7d5eb5e 100644 --- a/12-templating.html +++ b/12-templating.html @@ -172,7 +172,7 @@

    Twig

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 0a2a415..577dadf 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -170,7 +170,7 @@

    Running Psalm

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 6fc32df..3c1294d 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -174,7 +174,7 @@

    What next?

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    diff --git a/index.html b/index.html index fbf873b..4980f36 100644 --- a/index.html +++ b/index.html @@ -121,7 +121,7 @@

    Approach

    Copyright Barney Laurance
    - Site generated from sources at 02:02 London time on + Site generated from sources at 02:05 London time on Sun 01 Mar 2020.
    From 047b7f39c00c266509504dace112f0be8889d918 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 1 Mar 2020 02:13:18 +0000 Subject: [PATCH 25/40] Update GH Pages based on CircleCI Build 136 [ci skip] --- 01-introduction.html | 9 ++------- 02-getting-php.html | 9 ++------- 03-hello-world.html | 9 ++------- 04-http.html | 9 ++------- 05-variables.html | 9 ++------- 06-functions.html | 9 ++------- 07-classes-1.html | 9 ++------- 08-classes-2.html | 9 ++------- 09-classes-3.html | 9 ++------- 10-testing.html | 9 ++------- 11-databases.html | 9 ++------- 12-templating.html | 9 ++------- 13-static-analysis.html | 9 ++------- 14-what-next.html | 9 ++------- css/styles.css | 3 ++- index.html | 9 ++------- 16 files changed, 32 insertions(+), 106 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 4980f36..7ddc8cf 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -102,26 +102,21 @@

    Approach

    ways to use PHP, and ignore most of the things that PHP allows you to do but you probably shouldn't.

    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    - - - - -
    diff --git a/02-getting-php.html b/02-getting-php.html index 250f2ad..d098697 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -128,7 +128,7 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index 7808e79..1af6322 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -120,7 +120,7 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/04-http.html b/04-http.html index 023d959..46ec3b5 100644 --- a/04-http.html +++ b/04-http.html @@ -111,7 +111,7 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/05-variables.html b/05-variables.html index cb63cbf..7be93ed 100644 --- a/05-variables.html +++ b/05-variables.html @@ -174,7 +174,7 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/06-functions.html b/06-functions.html index 62c269d..0416205 100644 --- a/06-functions.html +++ b/06-functions.html @@ -131,7 +131,7 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 9d4a6bd..c8e402b 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -198,7 +198,7 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 72799ab..daf0569 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -188,7 +188,7 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 2e03423..214a779 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -198,7 +198,7 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/10-testing.html b/10-testing.html index 41c12ea..00c2617 100644 --- a/10-testing.html +++ b/10-testing.html @@ -205,7 +205,7 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/11-databases.html b/11-databases.html index a3f594b..ea9e0fd 100644 --- a/11-databases.html +++ b/11-databases.html @@ -276,7 +276,7 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/12-templating.html b/12-templating.html index 8476671..f270794 100644 --- a/12-templating.html +++ b/12-templating.html @@ -168,7 +168,7 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 5a9f484..915089d 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -166,7 +166,7 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 31750c4..1c2cdba 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -170,7 +170,7 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    diff --git a/index.html b/index.html index faa97c4..58307bf 100644 --- a/index.html +++ b/index.html @@ -117,7 +117,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 02:14 London time on + at 12:03 London time on Sun 01 Mar 2020.
    From 281036b52b164388ea9b341400af71db3a13fb01 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Mon, 2 Mar 2020 22:17:16 +0000 Subject: [PATCH 28/40] Update GH Pages based on CircleCI Build 145 [ci skip] --- 01-introduction.html | 8 +++++--- 02-getting-php.html | 8 +++++--- 03-hello-world.html | 8 +++++--- 04-http.html | 8 +++++--- 05-variables.html | 8 +++++--- 06-functions.html | 8 +++++--- 07-classes-1.html | 8 +++++--- 08-classes-2.html | 8 +++++--- 09-classes-3.html | 8 +++++--- 10-testing.html | 8 +++++--- 11-databases.html | 8 +++++--- 12-templating.html | 8 +++++--- 13-static-analysis.html | 8 +++++--- 14-what-next.html | 8 +++++--- index.html | 8 +++++--- 15 files changed, 75 insertions(+), 45 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 58307bf..56badf1 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -3,6 +3,8 @@ + + Introduction | A Moderately Short PHP Tutorial @@ -117,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -126,4 +128,4 @@

    Approach

    - \ No newline at end of file + diff --git a/02-getting-php.html b/02-getting-php.html index d098697..64c33e6 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -3,6 +3,8 @@ + + Getting PHP | A Moderately Short PHP Tutorial @@ -128,8 +130,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -137,4 +139,4 @@

    Windows

    - \ No newline at end of file + diff --git a/03-hello-world.html b/03-hello-world.html index 1af6322..3d443e2 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -3,6 +3,8 @@ + + Hello, world | A Moderately Short PHP Tutorial @@ -120,8 +122,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -129,4 +131,4 @@

    Hello, world

    - \ No newline at end of file + diff --git a/04-http.html b/04-http.html index 46ec3b5..a7bd79c 100644 --- a/04-http.html +++ b/04-http.html @@ -3,6 +3,8 @@ + + HTTP | A Moderately Short PHP Tutorial @@ -111,8 +113,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -120,4 +122,4 @@

    HTTP

    - \ No newline at end of file + diff --git a/05-variables.html b/05-variables.html index 7be93ed..ecfe9a3 100644 --- a/05-variables.html +++ b/05-variables.html @@ -3,6 +3,8 @@ + + Variables, arrays and loops | A Moderately Short PHP Tutorial @@ -174,8 +176,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -183,4 +185,4 @@

    Associative arrays

    - \ No newline at end of file + diff --git a/06-functions.html b/06-functions.html index 0416205..7ad0e39 100644 --- a/06-functions.html +++ b/06-functions.html @@ -3,6 +3,8 @@ + + Functions | A Moderately Short PHP Tutorial @@ -131,8 +133,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -140,4 +142,4 @@

    Functions

    - \ No newline at end of file + diff --git a/07-classes-1.html b/07-classes-1.html index c8e402b..6d011a7 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -3,6 +3,8 @@ + + Classes and Objects | A Moderately Short PHP Tutorial @@ -198,8 +200,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -207,4 +209,4 @@

    What's in the class

    - \ No newline at end of file + diff --git a/08-classes-2.html b/08-classes-2.html index daf0569..5b5408e 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -3,6 +3,8 @@ + + Classes and Composer | A Moderately Short PHP Tutorial @@ -188,8 +190,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -197,4 +199,4 @@

    Composer

    - \ No newline at end of file + diff --git a/09-classes-3.html b/09-classes-3.html index 214a779..0082405 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -3,6 +3,8 @@ + + Classes, Static Methods, and Object Identity | A Moderately Short PHP Tutorial @@ -198,8 +200,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -207,4 +209,4 @@

    Object Identity

    - \ No newline at end of file + diff --git a/10-testing.html b/10-testing.html index 00c2617..6eb4518 100644 --- a/10-testing.html +++ b/10-testing.html @@ -3,6 +3,8 @@ + + Testing | A Moderately Short PHP Tutorial @@ -205,8 +207,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -214,4 +216,4 @@

    Writing a test

    - \ No newline at end of file + diff --git a/11-databases.html b/11-databases.html index ea9e0fd..60603b5 100644 --- a/11-databases.html +++ b/11-databases.html @@ -3,6 +3,8 @@ + + Databases | A Moderately Short PHP Tutorial @@ -276,8 +278,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -285,4 +287,4 @@

    Other Database Engines.

    - \ No newline at end of file + diff --git a/12-templating.html b/12-templating.html index f270794..8c49dc1 100644 --- a/12-templating.html +++ b/12-templating.html @@ -3,6 +3,8 @@ + + Templating | A Moderately Short PHP Tutorial @@ -168,8 +170,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -177,4 +179,4 @@

    Twig

    - \ No newline at end of file + diff --git a/13-static-analysis.html b/13-static-analysis.html index 915089d..4c38804 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -3,6 +3,8 @@ + + Static Analysis | A Moderately Short PHP Tutorial @@ -166,8 +168,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -175,4 +177,4 @@

    Running Psalm

    - \ No newline at end of file + diff --git a/14-what-next.html b/14-what-next.html index 1c2cdba..3a0704d 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -3,6 +3,8 @@ + + What next? | A Moderately Short PHP Tutorial @@ -170,8 +172,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -179,4 +181,4 @@

    What next?

    - \ No newline at end of file + diff --git a/index.html b/index.html index 58307bf..56badf1 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,8 @@ + + Introduction | A Moderately Short PHP Tutorial @@ -117,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 12:03 London time on - Sun 01 Mar 2020. + at 22:17 London time on + Mon 02 Mar 2020.
    @@ -126,4 +128,4 @@

    Approach

    - \ No newline at end of file + From 2e2ce41a9bf094a11e4cc508d3b1c523c26c5813 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Mon, 2 Mar 2020 22:24:06 +0000 Subject: [PATCH 29/40] Update GH Pages based on CircleCI Build 148 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- 13-static-analysis.html | 2 +- 14-what-next.html | 2 +- css/styles.css | 17 ++++++++--------- index.html | 2 +- 16 files changed, 23 insertions(+), 24 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 56badf1..df14a02 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -119,7 +119,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 64c33e6..952c25d 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -130,7 +130,7 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index 3d443e2..af9feaf 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -122,7 +122,7 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/04-http.html b/04-http.html index a7bd79c..a0a1b1e 100644 --- a/04-http.html +++ b/04-http.html @@ -113,7 +113,7 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/05-variables.html b/05-variables.html index ecfe9a3..c3fc9a7 100644 --- a/05-variables.html +++ b/05-variables.html @@ -176,7 +176,7 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/06-functions.html b/06-functions.html index 7ad0e39..8252c69 100644 --- a/06-functions.html +++ b/06-functions.html @@ -133,7 +133,7 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 6d011a7..575e886 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -200,7 +200,7 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 5b5408e..7770305 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -190,7 +190,7 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 0082405..b7b64ec 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -200,7 +200,7 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/10-testing.html b/10-testing.html index 6eb4518..83c4faa 100644 --- a/10-testing.html +++ b/10-testing.html @@ -207,7 +207,7 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/11-databases.html b/11-databases.html index 60603b5..e4bdd2e 100644 --- a/11-databases.html +++ b/11-databases.html @@ -278,7 +278,7 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/12-templating.html b/12-templating.html index 8c49dc1..640d474 100644 --- a/12-templating.html +++ b/12-templating.html @@ -170,7 +170,7 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 4c38804..936de86 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -168,7 +168,7 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 3a0704d..c0c8a14 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -172,7 +172,7 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    diff --git a/css/styles.css b/css/styles.css index bcfcff8..0bc453f 100644 --- a/css/styles.css +++ b/css/styles.css @@ -4,31 +4,30 @@ justify-content: center; flex-flow: column wrap; align-content: stretch; - max-height: 13em; } -@media (max-width: 1000px) { +@media (min-width: 1000px) { #pages ul { - max-height: none; + max-height: 13em; } } #pages ul li { - margin: 0.2em 1em; + margin: 0.2em 1em 0.2em 0; min-width: 20em; - display: block; + list-style: none; flex: 1 1 0; - border-bottom: 0.1em rgba(0,0,0,0) solid; - padding-bottom: 0.1em; + border-bottom: 1px transparent solid; + padding-bottom: 1px; } #pages ul li.current { - list-style: disc; - border-bottom-color: black; + border-bottom-color: inherit; } #pages ul li.current a { color: inherit; + text-decoration: none; } body > div { diff --git a/index.html b/index.html index 56badf1..df14a02 100644 --- a/index.html +++ b/index.html @@ -119,7 +119,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 22:17 London time on + at 22:23 London time on Mon 02 Mar 2020.
    From 2a6ac9181c099ba5f90d5c7634f12436ce851cdc Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 7 Mar 2020 11:35:04 +0000 Subject: [PATCH 30/40] Update GH Pages based on CircleCI Build 151 [ci skip] --- 01-introduction.html | 6 +++--- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 6 +++--- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index df14a02..5cf52fb 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -90,7 +90,7 @@

    Who is this for?

    You should probably already know at least one programming language with curly braces, if conditions, variables, functions and loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, -you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and +you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons with Javascript and Typescript.

    Why did I write it?

    I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 952c25d..2fb929b 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -130,8 +130,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index af9feaf..6b4e337 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -122,8 +122,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/04-http.html b/04-http.html index a0a1b1e..092da5d 100644 --- a/04-http.html +++ b/04-http.html @@ -113,8 +113,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/05-variables.html b/05-variables.html index c3fc9a7..f21927b 100644 --- a/05-variables.html +++ b/05-variables.html @@ -176,8 +176,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/06-functions.html b/06-functions.html index 8252c69..480a8c1 100644 --- a/06-functions.html +++ b/06-functions.html @@ -133,8 +133,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 575e886..99b88dc 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -200,8 +200,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 7770305..7ed5735 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -190,8 +190,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index b7b64ec..3baeec3 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -200,8 +200,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/10-testing.html b/10-testing.html index 83c4faa..c350fa3 100644 --- a/10-testing.html +++ b/10-testing.html @@ -207,8 +207,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/11-databases.html b/11-databases.html index e4bdd2e..9ccab32 100644 --- a/11-databases.html +++ b/11-databases.html @@ -278,8 +278,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/12-templating.html b/12-templating.html index 640d474..2ca3918 100644 --- a/12-templating.html +++ b/12-templating.html @@ -170,8 +170,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 936de86..074dc0e 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -168,8 +168,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/14-what-next.html b/14-what-next.html index c0c8a14..71e2777 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -172,8 +172,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    diff --git a/index.html b/index.html index df14a02..5cf52fb 100644 --- a/index.html +++ b/index.html @@ -90,7 +90,7 @@

    Who is this for?

    You should probably already know at least one programming language with curly braces, if conditions, variables, functions and loops. The most likely scenario is that you are a Javascript or Typescript developer, working on a team that uses a combination of PHP and JS or TS, and while you might not currently need deep PHP knowledge, -you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons between with Javascript and +you want 'T-shaped skills', involving basic PHP knowledge. There will be some comparisons with Javascript and Typescript.

    Why did I write it?

    I work as a PHP developer, and have some colleagues with great Javascript skills who sometimes want to do work in the PHP @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 22:23 London time on - Mon 02 Mar 2020. + at 11:34 London time on + Sat 07 Mar 2020.
    From fb853147c729c06a17e95502e9270b98e0321518 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Wed, 11 Mar 2020 20:39:26 +0000 Subject: [PATCH 31/40] Update GH Pages based on CircleCI Build 154 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 6 +++--- 09-classes-3.html | 4 ++-- 10-testing.html | 6 +++--- 11-databases.html | 6 +++--- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 4 ++-- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 5cf52fb..e3dd24a 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 2fb929b..699e79f 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -130,8 +130,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index 6b4e337..10a8234 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -122,8 +122,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/04-http.html b/04-http.html index 092da5d..4a5379e 100644 --- a/04-http.html +++ b/04-http.html @@ -113,8 +113,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/05-variables.html b/05-variables.html index f21927b..c35a786 100644 --- a/05-variables.html +++ b/05-variables.html @@ -176,8 +176,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/06-functions.html b/06-functions.html index 480a8c1..ecc1bae 100644 --- a/06-functions.html +++ b/06-functions.html @@ -133,8 +133,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 99b88dc..be28955 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -200,8 +200,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 7ed5735..21500ac 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -93,7 +93,7 @@

    Classes and Composer

    By convention, and to follow the PSR-1 coding standard, we always put the entry point in a separate file to the class declaration.

    Let's write a simple script to create a planet and print out its details. Since at the moment Planet is just a data -holder the script won't be too exiting.

    +holder the script won't be too exciting.

    Write the following in a file called start.php

    <?php declare(strict_types=1);
     
    @@ -190,8 +190,8 @@ 

    Composer

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 3baeec3..88dc081 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -200,8 +200,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/10-testing.html b/10-testing.html index c350fa3..bb6e3ca 100644 --- a/10-testing.html +++ b/10-testing.html @@ -114,7 +114,7 @@

    Installing PHPUnit

    Composer has also created a new file for us, composer.lock. This has metadata about the exact versions of the packages installed. At the time of writing it shows me that PHPUnit is at version 9.0.1, and I can see the details of 29 other packages that have been installed because PHPUnit depends on them directly or indirectly. The composer show command -will output the list of installed packages in a much more consice format.

    +will output the list of installed packages in a much more concise format.

    Writing a test

    Let's write our first test. Create a test subdirectory next to src, and write the following in test/PlanetTest.php

    <?php declare(strict_types=1);
    @@ -207,8 +207,8 @@ 

    Writing a test

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/11-databases.html b/11-databases.html index 9ccab32..0ff836d 100644 --- a/11-databases.html +++ b/11-databases.html @@ -110,7 +110,7 @@

    Linux

    Once you've found the package name, e.g. php7.4-sqlite3 install it with a command such as

    sudo apt install php7.4-sqlite3.

    Mac

    -

    If you installed PHP via homebrew, I think will automatically have come with SQLite built in and enabled.

    +

    If you installed PHP via homebrew, I think it will automatically have come with SQLite built in and enabled.

    Windows

    If you installed PHP as part of XAMPP this should have SQLite enabled by default.

    Creating a database

    @@ -278,8 +278,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/12-templating.html b/12-templating.html index 2ca3918..b6e4903 100644 --- a/12-templating.html +++ b/12-templating.html @@ -170,8 +170,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 074dc0e..8b5616a 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -168,8 +168,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 71e2777..1bce28a 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -172,8 +172,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    diff --git a/index.html b/index.html index 5cf52fb..e3dd24a 100644 --- a/index.html +++ b/index.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 11:34 London time on - Sat 07 Mar 2020. + at 20:38 London time on + Wed 11 Mar 2020.
    From 6a9b48e58648fd5473699921b1b3bf69478c57b6 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 21 Jun 2020 14:09:08 +0000 Subject: [PATCH 32/40] Update GH Pages based on CircleCI Build 157 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 6 +++--- index.html | 4 ++-- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index e3dd24a..d59a029 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 699e79f..d4727f0 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -130,8 +130,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index 10a8234..cbe1035 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -122,8 +122,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/04-http.html b/04-http.html index 4a5379e..1f69deb 100644 --- a/04-http.html +++ b/04-http.html @@ -113,8 +113,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/05-variables.html b/05-variables.html index c35a786..345331a 100644 --- a/05-variables.html +++ b/05-variables.html @@ -176,8 +176,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/06-functions.html b/06-functions.html index ecc1bae..9658f50 100644 --- a/06-functions.html +++ b/06-functions.html @@ -133,8 +133,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index be28955..66488f0 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -200,8 +200,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 21500ac..72eb2ce 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -190,8 +190,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 88dc081..8fac629 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -200,8 +200,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/10-testing.html b/10-testing.html index bb6e3ca..11dd24e 100644 --- a/10-testing.html +++ b/10-testing.html @@ -207,8 +207,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/11-databases.html b/11-databases.html index 0ff836d..dcff7eb 100644 --- a/11-databases.html +++ b/11-databases.html @@ -278,8 +278,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/12-templating.html b/12-templating.html index b6e4903..504947b 100644 --- a/12-templating.html +++ b/12-templating.html @@ -170,8 +170,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 8b5616a..cb5a02b 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -168,8 +168,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 1bce28a..2151706 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -142,7 +142,7 @@

    What next?

  • Subscribe to PHP Annotated Monthly from the makers of -PhpStorm, for interesting links every Month.

    +PhpStorm, for interesting links every month.

  • And finally, read Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing @@ -172,8 +172,8 @@

    What next?

    © Barney Laurance
    Site generated from
    sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020. diff --git a/index.html b/index.html index e3dd24a..d59a029 100644 --- a/index.html +++ b/index.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:38 London time on - Wed 11 Mar 2020. + at 15:08 London time on + Sun 21 Jun 2020.
    From 84d840aa99ee86e31013826131f96110985eb8a1 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sun, 28 Jun 2020 11:25:10 +0000 Subject: [PATCH 33/40] Update GH Pages based on CircleCI Build 160 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 6 +++--- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 4 ++-- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index d59a029..4215b6a 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index d4727f0..282583f 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -88,7 +88,7 @@

    Getting PHP

    If you just want to run a PHP one-liner, or experiment with a tiny throwaway PHP script, the easiest way is probably online at 3v4l, but to work through this tutorial you should have PHP installed on your computer.

    Installation

    -

    First check if you already have PHP installed. Open your command-line prompt, and type php --v. If you have PHP, you +

    First check if you already have PHP installed. Open your command-line prompt, and type php -v. If you have PHP, you should see something like:

    PHP 7.4.2 (cli) (built: Jan 23 2020 11:21:30) ( NTS )
     Copyright (c) The PHP Group
    @@ -130,8 +130,8 @@ 

    Windows

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index cbe1035..7f65067 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -122,8 +122,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/04-http.html b/04-http.html index 1f69deb..beb2ef4 100644 --- a/04-http.html +++ b/04-http.html @@ -113,8 +113,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/05-variables.html b/05-variables.html index 345331a..96ad2f2 100644 --- a/05-variables.html +++ b/05-variables.html @@ -176,8 +176,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/06-functions.html b/06-functions.html index 9658f50..a2db190 100644 --- a/06-functions.html +++ b/06-functions.html @@ -133,8 +133,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 66488f0..aad4515 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -200,8 +200,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 72eb2ce..c4e84fe 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -190,8 +190,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 8fac629..202b413 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -200,8 +200,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/10-testing.html b/10-testing.html index 11dd24e..4bb9bd7 100644 --- a/10-testing.html +++ b/10-testing.html @@ -207,8 +207,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/11-databases.html b/11-databases.html index dcff7eb..d416061 100644 --- a/11-databases.html +++ b/11-databases.html @@ -278,8 +278,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/12-templating.html b/12-templating.html index 504947b..37ce8d2 100644 --- a/12-templating.html +++ b/12-templating.html @@ -170,8 +170,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index cb5a02b..327c633 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -168,8 +168,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/14-what-next.html b/14-what-next.html index 2151706..743706e 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -172,8 +172,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    diff --git a/index.html b/index.html index d59a029..4215b6a 100644 --- a/index.html +++ b/index.html @@ -119,8 +119,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 15:08 London time on - Sun 21 Jun 2020. + at 12:24 London time on + Sun 28 Jun 2020.
    From 36fc8cbd735307a23492e45ea8ed282cb30d79f5 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Sat, 8 Aug 2020 20:32:17 +0000 Subject: [PATCH 34/40] Update GH Pages based on CircleCI Build 164 [ci skip] --- 01-introduction.html | 6 +++--- 02-getting-php.html | 6 +++--- 03-hello-world.html | 6 +++--- 04-http.html | 6 +++--- 05-variables.html | 6 +++--- 06-functions.html | 6 +++--- 07-classes-1.html | 6 +++--- 08-classes-2.html | 6 +++--- 09-classes-3.html | 6 +++--- 10-testing.html | 6 +++--- 11-databases.html | 6 +++--- 12-templating.html | 6 +++--- 13-static-analysis.html | 6 +++--- 14-what-next.html | 6 +++--- index.html | 6 +++--- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 4215b6a..81afd4b 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -117,10 +117,10 @@

    Approach

    diff --git a/02-getting-php.html b/02-getting-php.html index 282583f..04aeb15 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -128,10 +128,10 @@

    Windows

    diff --git a/03-hello-world.html b/03-hello-world.html index 7f65067..f691dae 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -120,10 +120,10 @@

    Hello, world

    diff --git a/04-http.html b/04-http.html index beb2ef4..5c173d3 100644 --- a/04-http.html +++ b/04-http.html @@ -111,10 +111,10 @@

    HTTP

    diff --git a/05-variables.html b/05-variables.html index 96ad2f2..8478a14 100644 --- a/05-variables.html +++ b/05-variables.html @@ -174,10 +174,10 @@

    Associative arrays

    diff --git a/06-functions.html b/06-functions.html index a2db190..bc4cc96 100644 --- a/06-functions.html +++ b/06-functions.html @@ -131,10 +131,10 @@

    Functions

    diff --git a/07-classes-1.html b/07-classes-1.html index aad4515..56b694c 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -198,10 +198,10 @@

    What's in the class

    diff --git a/08-classes-2.html b/08-classes-2.html index c4e84fe..8b1d376 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -188,10 +188,10 @@

    Composer

    diff --git a/09-classes-3.html b/09-classes-3.html index 202b413..90b4adc 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -198,10 +198,10 @@

    Object Identity

    diff --git a/10-testing.html b/10-testing.html index 4bb9bd7..04fbf78 100644 --- a/10-testing.html +++ b/10-testing.html @@ -205,10 +205,10 @@

    Writing a test

    diff --git a/11-databases.html b/11-databases.html index d416061..0f480ad 100644 --- a/11-databases.html +++ b/11-databases.html @@ -276,10 +276,10 @@

    Other Database Engines.

    diff --git a/12-templating.html b/12-templating.html index 37ce8d2..985717e 100644 --- a/12-templating.html +++ b/12-templating.html @@ -168,10 +168,10 @@

    Twig

    diff --git a/13-static-analysis.html b/13-static-analysis.html index 327c633..7a6db53 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -166,10 +166,10 @@

    Running Psalm

    diff --git a/14-what-next.html b/14-what-next.html index 743706e..a832be0 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -170,10 +170,10 @@

    What next?

    diff --git a/index.html b/index.html index 4215b6a..81afd4b 100644 --- a/index.html +++ b/index.html @@ -117,10 +117,10 @@

    Approach

    From 8da7722592b1ba6e23983ba0d7d43c0f79281b66 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Fri, 28 Aug 2020 19:46:32 +0000 Subject: [PATCH 35/40] Update GH Pages based on CircleCI Build 167 [ci skip] --- 01-introduction.html | 21 ++++----------------- 02-getting-php.html | 21 ++++----------------- 03-hello-world.html | 21 ++++----------------- 04-http.html | 21 ++++----------------- 05-variables.html | 21 ++++----------------- 06-functions.html | 21 ++++----------------- 07-classes-1.html | 21 ++++----------------- 08-classes-2.html | 21 ++++----------------- 09-classes-3.html | 21 ++++----------------- 10-testing.html | 21 ++++----------------- 11-databases.html | 21 ++++----------------- 12-templating.html | 21 ++++----------------- 13-static-analysis.html | 21 ++++----------------- 14-what-next.html | 21 ++++----------------- index.html | 21 ++++----------------- 15 files changed, 60 insertions(+), 255 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 81afd4b..adfcbdf 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -13,21 +13,8 @@ - - - + + @@ -119,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/02-getting-php.html b/02-getting-php.html index 04aeb15..cca6801 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -13,21 +13,8 @@ - - - + + @@ -130,8 +117,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/03-hello-world.html b/03-hello-world.html index f691dae..e5ad7a0 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -13,21 +13,8 @@ - - - + + @@ -122,8 +109,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/04-http.html b/04-http.html index 5c173d3..d32342a 100644 --- a/04-http.html +++ b/04-http.html @@ -13,21 +13,8 @@ - - - + + @@ -113,8 +100,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/05-variables.html b/05-variables.html index 8478a14..d7078f6 100644 --- a/05-variables.html +++ b/05-variables.html @@ -13,21 +13,8 @@ - - - + + @@ -176,8 +163,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/06-functions.html b/06-functions.html index bc4cc96..5327e92 100644 --- a/06-functions.html +++ b/06-functions.html @@ -13,21 +13,8 @@ - - - + + @@ -133,8 +120,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/07-classes-1.html b/07-classes-1.html index 56b694c..8b48ac0 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -13,21 +13,8 @@ - - - + + @@ -200,8 +187,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/08-classes-2.html b/08-classes-2.html index 8b1d376..bb6d766 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -13,21 +13,8 @@ - - - + + @@ -190,8 +177,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/09-classes-3.html b/09-classes-3.html index 90b4adc..12c2cc9 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -13,21 +13,8 @@ - - - + + @@ -200,8 +187,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/10-testing.html b/10-testing.html index 04fbf78..2d83294 100644 --- a/10-testing.html +++ b/10-testing.html @@ -13,21 +13,8 @@ - - - + + @@ -207,8 +194,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/11-databases.html b/11-databases.html index 0f480ad..5a351a6 100644 --- a/11-databases.html +++ b/11-databases.html @@ -13,21 +13,8 @@ - - - + + @@ -278,8 +265,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/12-templating.html b/12-templating.html index 985717e..e9eac73 100644 --- a/12-templating.html +++ b/12-templating.html @@ -13,21 +13,8 @@ - - - + + @@ -170,8 +157,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 7a6db53..af6bb67 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -13,21 +13,8 @@ - - - + + @@ -168,8 +155,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/14-what-next.html b/14-what-next.html index a832be0..d215d3f 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -13,21 +13,8 @@ - - - + + @@ -172,8 +159,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    diff --git a/index.html b/index.html index 81afd4b..adfcbdf 100644 --- a/index.html +++ b/index.html @@ -13,21 +13,8 @@ - - - + + @@ -119,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 21:31 London time on - Sat 08 Aug 2020. + at 20:46 London time on + Fri 28 Aug 2020.
    From 042cdcb3d507a069b17ef379235ea009dbd8fab6 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Wed, 17 Feb 2021 20:27:40 +0000 Subject: [PATCH 36/40] Update GH Pages based on CircleCI Build 170 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 6 +++--- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 4 ++-- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index adfcbdf..a0fe332 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/02-getting-php.html b/02-getting-php.html index cca6801..b87b3b9 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -117,8 +117,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/03-hello-world.html b/03-hello-world.html index e5ad7a0..ea2f421 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -109,8 +109,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/04-http.html b/04-http.html index d32342a..7515f56 100644 --- a/04-http.html +++ b/04-http.html @@ -100,8 +100,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/05-variables.html b/05-variables.html index d7078f6..476371d 100644 --- a/05-variables.html +++ b/05-variables.html @@ -163,8 +163,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/06-functions.html b/06-functions.html index 5327e92..9054a53 100644 --- a/06-functions.html +++ b/06-functions.html @@ -120,8 +120,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/07-classes-1.html b/07-classes-1.html index 8b48ac0..290cc87 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -187,8 +187,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/08-classes-2.html b/08-classes-2.html index bb6d766..a056935 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -177,8 +177,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/09-classes-3.html b/09-classes-3.html index 12c2cc9..56d44b8 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -187,8 +187,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/10-testing.html b/10-testing.html index 2d83294..3cad834 100644 --- a/10-testing.html +++ b/10-testing.html @@ -194,8 +194,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/11-databases.html b/11-databases.html index 5a351a6..c84e91f 100644 --- a/11-databases.html +++ b/11-databases.html @@ -265,8 +265,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/12-templating.html b/12-templating.html index e9eac73..71f4c0b 100644 --- a/12-templating.html +++ b/12-templating.html @@ -135,7 +135,7 @@

    Twig

    expect to have a planet variable, and it will be of type Planet. Add the following to the top of the file:

    In Twig we use double curly brackets to output dynamic data: Replace Some Planet with -, and replace `34601` with. Twig knows that we mean getName and +{{planet.name}}, and replace 34601 with {{planet.populationSize}}. Twig knows that we mean getName and getPopulationSize, so we don't have to write those function names out in full.

    If you reload the page you should now see the planet details in their proper places.

    Twig is a full featured special purpose programming language, with features like loops, conditionals, filters, @@ -157,8 +157,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index af6bb67..cd78f14 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -155,8 +155,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/14-what-next.html b/14-what-next.html index d215d3f..5c63909 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -159,8 +159,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    diff --git a/index.html b/index.html index adfcbdf..a0fe332 100644 --- a/index.html +++ b/index.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:46 London time on - Fri 28 Aug 2020. + at 20:27 London time on + Wed 17 Feb 2021.
    From d277e43aef5f3d58b92310e736b788f5a6dff0d3 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 29 Jun 2021 12:25:16 +0000 Subject: [PATCH 37/40] Update GH Pages based on CircleCI Build 173 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 4 ++-- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index a0fe332..60e3ecc 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/02-getting-php.html b/02-getting-php.html index b87b3b9..a162742 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -117,8 +117,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/03-hello-world.html b/03-hello-world.html index ea2f421..127f369 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -109,8 +109,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/04-http.html b/04-http.html index 7515f56..e1bf276 100644 --- a/04-http.html +++ b/04-http.html @@ -100,8 +100,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/05-variables.html b/05-variables.html index 476371d..715eb13 100644 --- a/05-variables.html +++ b/05-variables.html @@ -163,8 +163,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/06-functions.html b/06-functions.html index 9054a53..412b4a3 100644 --- a/06-functions.html +++ b/06-functions.html @@ -120,8 +120,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/07-classes-1.html b/07-classes-1.html index 290cc87..8d13f60 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -187,8 +187,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/08-classes-2.html b/08-classes-2.html index a056935..fe46a49 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -177,8 +177,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/09-classes-3.html b/09-classes-3.html index 56d44b8..5019cbb 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -187,8 +187,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/10-testing.html b/10-testing.html index 3cad834..db7e042 100644 --- a/10-testing.html +++ b/10-testing.html @@ -194,8 +194,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/11-databases.html b/11-databases.html index c84e91f..eef1600 100644 --- a/11-databases.html +++ b/11-databases.html @@ -265,8 +265,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/12-templating.html b/12-templating.html index 71f4c0b..d3a1b5a 100644 --- a/12-templating.html +++ b/12-templating.html @@ -157,8 +157,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index cd78f14..8072665 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -155,8 +155,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/14-what-next.html b/14-what-next.html index 5c63909..3d5d152 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -159,8 +159,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    diff --git a/index.html b/index.html index a0fe332..60e3ecc 100644 --- a/index.html +++ b/index.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 20:27 London time on - Wed 17 Feb 2021. + at 13:25 London time on + Tue 29 Jun 2021.
    From f8a13cde09c86b5286aa99719ffb239f350738a8 Mon Sep 17 00:00:00 2001 From: Circle CI Date: Tue, 29 Jun 2021 12:59:23 +0000 Subject: [PATCH 38/40] Update GH Pages based on CircleCI Build 176 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- 13-static-analysis.html | 2 +- 14-what-next.html | 2 +- index.html | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 60e3ecc..8bfe22e 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -106,7 +106,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/02-getting-php.html b/02-getting-php.html index a162742..30d7e41 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -117,7 +117,7 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/03-hello-world.html b/03-hello-world.html index 127f369..640611e 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -109,7 +109,7 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/04-http.html b/04-http.html index e1bf276..1e84527 100644 --- a/04-http.html +++ b/04-http.html @@ -100,7 +100,7 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/05-variables.html b/05-variables.html index 715eb13..41d7766 100644 --- a/05-variables.html +++ b/05-variables.html @@ -163,7 +163,7 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/06-functions.html b/06-functions.html index 412b4a3..bd1f2b7 100644 --- a/06-functions.html +++ b/06-functions.html @@ -120,7 +120,7 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/07-classes-1.html b/07-classes-1.html index 8d13f60..70d383e 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -187,7 +187,7 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/08-classes-2.html b/08-classes-2.html index fe46a49..cdd3aa8 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -177,7 +177,7 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/09-classes-3.html b/09-classes-3.html index 5019cbb..95e93e8 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -187,7 +187,7 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/10-testing.html b/10-testing.html index db7e042..bdf68cb 100644 --- a/10-testing.html +++ b/10-testing.html @@ -194,7 +194,7 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/11-databases.html b/11-databases.html index eef1600..37095aa 100644 --- a/11-databases.html +++ b/11-databases.html @@ -265,7 +265,7 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/12-templating.html b/12-templating.html index d3a1b5a..ddc6423 100644 --- a/12-templating.html +++ b/12-templating.html @@ -157,7 +157,7 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index 8072665..a28bac4 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -155,7 +155,7 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/14-what-next.html b/14-what-next.html index 3d5d152..4a36cb0 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -159,7 +159,7 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    diff --git a/index.html b/index.html index 60e3ecc..8bfe22e 100644 --- a/index.html +++ b/index.html @@ -106,7 +106,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 13:25 London time on + at 13:59 London time on Tue 29 Jun 2021.
    From 75be24be87a65a4701a6db8c3c8bca252e9852ed Mon Sep 17 00:00:00 2001 From: Circle CI Date: Fri, 11 Feb 2022 02:33:00 +0000 Subject: [PATCH 39/40] Update GH Pages based on CircleCI Build 179 [ci skip] --- 01-introduction.html | 4 ++-- 02-getting-php.html | 4 ++-- 03-hello-world.html | 4 ++-- 04-http.html | 4 ++-- 05-variables.html | 4 ++-- 06-functions.html | 4 ++-- 07-classes-1.html | 4 ++-- 08-classes-2.html | 4 ++-- 09-classes-3.html | 4 ++-- 10-testing.html | 4 ++-- 11-databases.html | 4 ++-- 12-templating.html | 4 ++-- 13-static-analysis.html | 4 ++-- 14-what-next.html | 4 ++-- index.html | 4 ++-- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index 8bfe22e..c1f2485 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/02-getting-php.html b/02-getting-php.html index 30d7e41..03d374f 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -117,8 +117,8 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/03-hello-world.html b/03-hello-world.html index 640611e..a2160a3 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -109,8 +109,8 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/04-http.html b/04-http.html index 1e84527..df8f3ec 100644 --- a/04-http.html +++ b/04-http.html @@ -100,8 +100,8 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/05-variables.html b/05-variables.html index 41d7766..de66a8f 100644 --- a/05-variables.html +++ b/05-variables.html @@ -163,8 +163,8 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/06-functions.html b/06-functions.html index bd1f2b7..108a2c5 100644 --- a/06-functions.html +++ b/06-functions.html @@ -120,8 +120,8 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/07-classes-1.html b/07-classes-1.html index 70d383e..c487b32 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -187,8 +187,8 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/08-classes-2.html b/08-classes-2.html index cdd3aa8..4d2318a 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -177,8 +177,8 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/09-classes-3.html b/09-classes-3.html index 95e93e8..725981a 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -187,8 +187,8 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/10-testing.html b/10-testing.html index bdf68cb..7bff3a4 100644 --- a/10-testing.html +++ b/10-testing.html @@ -194,8 +194,8 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/11-databases.html b/11-databases.html index 37095aa..60e9632 100644 --- a/11-databases.html +++ b/11-databases.html @@ -265,8 +265,8 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/12-templating.html b/12-templating.html index ddc6423..c84044a 100644 --- a/12-templating.html +++ b/12-templating.html @@ -157,8 +157,8 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index a28bac4..a604c1f 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -155,8 +155,8 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/14-what-next.html b/14-what-next.html index 4a36cb0..7bd8bcd 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -159,8 +159,8 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    diff --git a/index.html b/index.html index 8bfe22e..c1f2485 100644 --- a/index.html +++ b/index.html @@ -106,8 +106,8 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 13:59 London time on - Tue 29 Jun 2021. + at 02:32 London time on + Fri 11 Feb 2022.
    From 6807599c43eeb02056efaaf98ecebc5a3c55b94b Mon Sep 17 00:00:00 2001 From: Circle CI Date: Fri, 11 Feb 2022 23:56:00 +0000 Subject: [PATCH 40/40] Update GH Pages based on CircleCI Build 182 [ci skip] --- 01-introduction.html | 2 +- 02-getting-php.html | 2 +- 03-hello-world.html | 2 +- 04-http.html | 2 +- 05-variables.html | 2 +- 06-functions.html | 2 +- 07-classes-1.html | 2 +- 08-classes-2.html | 2 +- 09-classes-3.html | 2 +- 10-testing.html | 2 +- 11-databases.html | 2 +- 12-templating.html | 2 +- 13-static-analysis.html | 2 +- 14-what-next.html | 2 +- index.html | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/01-introduction.html b/01-introduction.html index c1f2485..947a6ff 100644 --- a/01-introduction.html +++ b/01-introduction.html @@ -106,7 +106,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/02-getting-php.html b/02-getting-php.html index 03d374f..608f69a 100644 --- a/02-getting-php.html +++ b/02-getting-php.html @@ -117,7 +117,7 @@

    Windows

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/03-hello-world.html b/03-hello-world.html index a2160a3..7a9eb63 100644 --- a/03-hello-world.html +++ b/03-hello-world.html @@ -109,7 +109,7 @@

    Hello, world

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/04-http.html b/04-http.html index df8f3ec..2e379c4 100644 --- a/04-http.html +++ b/04-http.html @@ -100,7 +100,7 @@

    HTTP

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/05-variables.html b/05-variables.html index de66a8f..1a0745b 100644 --- a/05-variables.html +++ b/05-variables.html @@ -163,7 +163,7 @@

    Associative arrays

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/06-functions.html b/06-functions.html index 108a2c5..f1ff618 100644 --- a/06-functions.html +++ b/06-functions.html @@ -120,7 +120,7 @@

    Functions

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/07-classes-1.html b/07-classes-1.html index c487b32..2711692 100644 --- a/07-classes-1.html +++ b/07-classes-1.html @@ -187,7 +187,7 @@

    What's in the class

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/08-classes-2.html b/08-classes-2.html index 4d2318a..c4bb13a 100644 --- a/08-classes-2.html +++ b/08-classes-2.html @@ -177,7 +177,7 @@

    Composer

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/09-classes-3.html b/09-classes-3.html index 725981a..a309aa9 100644 --- a/09-classes-3.html +++ b/09-classes-3.html @@ -187,7 +187,7 @@

    Object Identity

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/10-testing.html b/10-testing.html index 7bff3a4..6eafcc2 100644 --- a/10-testing.html +++ b/10-testing.html @@ -194,7 +194,7 @@

    Writing a test

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/11-databases.html b/11-databases.html index 60e9632..c546fa1 100644 --- a/11-databases.html +++ b/11-databases.html @@ -265,7 +265,7 @@

    Other Database Engines.

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/12-templating.html b/12-templating.html index c84044a..d489c51 100644 --- a/12-templating.html +++ b/12-templating.html @@ -157,7 +157,7 @@

    Twig

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/13-static-analysis.html b/13-static-analysis.html index a604c1f..d0654ca 100644 --- a/13-static-analysis.html +++ b/13-static-analysis.html @@ -155,7 +155,7 @@

    Running Psalm

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/14-what-next.html b/14-what-next.html index 7bd8bcd..3f2a216 100644 --- a/14-what-next.html +++ b/14-what-next.html @@ -159,7 +159,7 @@

    What next?

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.
    diff --git a/index.html b/index.html index c1f2485..947a6ff 100644 --- a/index.html +++ b/index.html @@ -106,7 +106,7 @@

    Approach

    © Barney Laurance
    Site generated from sources - at 02:32 London time on + at 23:55 London time on Fri 11 Feb 2022.