Skip to content

1. Introduction to PHP 7

The PDF of this document is available |HERE|.

The examples in this document are available |HERE|.

This document is part of a series of four articles:

  1. [Introduction to PHP 7 through Examples]. This is the current document;
  1. [Introduction to ECMASCRIPT 6 through examples];
  2. [Introduction to the VUE.JS framework through examples];
  3. [Introduction to the NUXT.JS framework framework ];

These are all documents for beginners. The articles follow a logical sequence but are loosely connected:

  • document [1] introduces the PHP 7 language. Readers interested only in PHP and not in the JavaScript covered in the following articles should stop here;
  • Documents [2–4] aim to build a JavaScript client for the tax calculation server developed in document [1];
  • The JavaScript frameworks [Vue.js] and [Nuxt.js] in Articles 3 and 4 require knowledge of the latest versions of ECMAScript, specifically version 6. Document [2] is therefore intended for those unfamiliar with this version of JavaScript. It refers to the tax calculation server built in document [1]. Readers of [2] will therefore sometimes need to refer back to document [1];
  • Once ECMASCRIPT 6 has been mastered, we can move on to the VUE.JS framework, which allows for the creation of JavaScript clients that run in a browser in SPA (Single Page Application) mode. This is document [3]. It refers both to the tax calculation server built in document [1] and to the standalone JavaScript client code built in [2]. Readers of [3] will therefore sometimes need to refer to documents [1] and [2];
  • Once you have mastered VUE.JS, you can move on to the NUXT.JS framework, which allows you to build JavaScript clients that run in a browser in SSR (Server Side Rendered) mode. It refers to the tax calculation server built in document [1], the standalone JavaScript client code built in [2], and the [vue.js] application developed in document [3]. Readers of [4] will therefore occasionally need to refer to documents [1], [2], and [3];

This document provides a list of PHP 7 console scripts in various areas (language structures, file access, database access, and internet network access). Web programming is addressed through web services. In this document, we refer to any web application that produces plain text as a web service. These are data servers, not web page servers, which are a mix of HTML, CSS, and JavaScript. We cover classic web concepts (HTTP protocol, JSON or XML responses, session management, authentication) also used in traditional web programming.

Nowadays, it is common to build web applications in client/server mode:

Image

  • in [1], the web browser displays web pages intended for a user [5, 7]. These pages contain JavaScript implementing a client for a data web service [2] as well as a client for a web page fragment server [3]. A well-established JS framework in this field is Google’s Angular 2 (May 2019);
  • in [2], the web server is a data server. It can be written in any language. It does not generate web pages in the traditional sense (HTML, CSS, JavaScript) except perhaps the first time. But this first page can be obtained from a traditional web server [3] (not a data server). The JavaScript on the initial page will then generate the application’s various web pages by retrieving the data [4] to be displayed from the web server, which acts as a data server [2]. It can also retrieve web page fragments [5] to format this data from the web page server [3];
  • in [4], the user initiates an action;
  • in [6,7]: they receive data formatted by a web page fragment;

In this document, we will write client/server applications in PHP 7 with the following structure:

Image

Here we have a client/server application written in PHP. A console script [9] will query a data server [4]. The knowledge gained here for writing the data service can be reused in a web application. The PHP data service can be retained, and the PHP client will be replaced by a JavaScript client.

As the central theme of this document, we will build a tax calculation service in 13 versions. Version 13 will have the following architecture:

Image

The server’s [web] layer will have an MVC (Model–View–Controller) architecture. The entire PHP 7 course is aimed at building this version.

The scripts in this document are commented, and their console output is reproduced. Additional explanations are provided where necessary. This document requires active reading: to understand a script, you must read its code, comments, and execution results.

The examples in this document are available |here|.

The PDF of the document can be found |here|.

Serge Tahé, July 2019