Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
PHP 8 Programming Tips, Tricks and Best Practices

You're reading from  PHP 8 Programming Tips, Tricks and Best Practices

Product type Book
Published in Aug 2021
Publisher Packt
ISBN-13 9781801071871
Pages 528 pages
Edition 1st Edition
Languages
Author (1):
Doug Bierer Doug Bierer
Profile icon Doug Bierer

Table of Contents (17) Chapters

Preface 1. Section 1: PHP 8 Tips
2. Chapter 1: Introducing New PHP 8 OOP Features 3. Chapter 2: Learning about PHP 8's Functional Additions 4. Chapter 3: Taking Advantage of Error-Handling Enhancements 5. Chapter 4: Making Direct C-Language Calls 6. Section 2: PHP 8 Tricks
7. Chapter 5: Discovering Potential OOP Backward-Compatibility Breaks 8. Chapter 6: Understanding PHP 8 Functional Differences 9. Chapter 7: Avoiding Traps When Using PHP 8 Extensions 10. Chapter 8: Learning about PHP 8's Deprecated or Removed Functionality 11. Section 3: PHP 8 Best Practices
12. Chapter 9: Mastering PHP 8 Best Practices 13. Chapter 10: Improving Performance 14. Chapter 11: Migrating Existing PHP Apps to PHP 8 15. Chapter 12: Creating PHP 8 Applications Using Asynchronous Programming 16. Other Books You May Enjoy

Technical requirements

To examine and run the code examples provided in this chapter, the minimum recommended hardware is listed here:

  • x86_64-based desktop PC or laptop
  • 1 gigabyte (GB) free disk space
  • 4 GB of random-access memory (RAM)
  • 500 kilobits per second (Kbps) or faster internet connection

In addition, you will need to install the following software:

  • Docker
  • Docker Compose

This book uses a pre-built Docker image that contains all the needed software to create and run the PHP 8 code examples covered in this book. You do not need to install PHP, Apache, or MySQL on your computer: just use Docker and the provided image.

To set up a test environment to run the code examples, proceed as follows:

  1. Install Docker.

    If you are running Windows, start here:

    https://docs.docker.com/docker-for-windows/install/

    If you are on a Mac, start here:

    https://docs.docker.com/docker-for-mac/install/

    If you are on Linux, have a look here:

    https://docs.docker.com/engine/install/

  2. Install Docker Compose. For all operating systems, start here:

    https://docs.docker.com/compose/install/

  3. Install the source code associated with this book onto your local computer.

    If you have installed Git, use the following command:

    git clone https://github.com/PacktPublishing/PHP-8-Programming-Tips-Tricks-and-Best-Practices.git ~/repo

    Otherwise, you can simply download the source code from this Uniform Resource Locator (URL): https://github.com/PacktPublishing/PHP-8-Programming-Tips-Tricks-and-Best-Practices/archive/main.zip. You can then unzip into a folder you create, which we refer to as /repo in this book.

  4. You can now start the Docker daemon running. For Windows or Mac, all you need to do is to activate the Docker Desktop app.

    If you are running Ubuntu or Debian Linux, issue this command:

    sudo service docker start

    For Red Hat, Fedora, or CentOS, use this command:

    sudo systemctl start docker

  5. Build a Docker container associated with this book and bring it online. To do so, proceed as follows.

    From your local computer, open Command Prompt (terminal window). Change the directory to /repo. For the first time only, issue the docker-compose build command to build the environment. Note that you might need root (administrator) privileges to run Docker commands. If this is the case, either run as administrator (for Windows) or preface the command with sudo. Depending on your connection speed, the initial build might take quite a bit of time to complete!

  6. To bring the container up, proceed as follows
  7. From your local computer, open Command Prompt (terminal window). Change the directory to /repo. Bring the Docker container online in background mode by running the following command:
    docker-compose up -d

    Note that you actually don't need to build the container separately. If the container is not built when you issue the docker-compose up command, it will be built automatically. On the other hand, it might be convenient to build the container separately, in which case docker build will suffice.

    Here's a useful command to ensure all containers are running:

    docker-compose ps
  8. To access the running Docker container web server, proceed as follows.

    Open the browser on your local computer. Enter this URL to access PHP 8 code:

    http://localhost:8888

    Enter this URL to access PHP 7 code:

    http://localhost:7777

  9. To open a command shell into the running Docker container, proceed as follows.

    From your local computer, open Command Prompt (terminal window). Issue this command to access the PHP 8 container:

    docker exec -it php8_tips_php8 /bin/bash 

    Issue this command to access the PHP 7 container:

    docker exec -it php8_tips_php7 /bin/bash
  10. When you are finished working with the container, to take it offline open Command Prompt (terminal window) from your local computer and issue this command:
    docker-compose down 

The source code for this chapter is located here:

https://github.com/PacktPublishing/PHP-8-Programming-Tips-Tricks-and-Best-Practices

Important note

If your host computer uses Advanced RISC Machines (ARM) architecture (for example, Raspberry Pi), you will need to use a modified Dockerfile.

Tip

It would be an excellent idea to get a quick overview of Docker technology and terms by reviewing this article: https://docs.docker.com/get-started/.

We can now begin our discussion by having a look at constructor property promotion.

You have been reading a chapter from
PHP 8 Programming Tips, Tricks and Best Practices
Published in: Aug 2021 Publisher: Packt ISBN-13: 9781801071871
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}