Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering PHP 7
Mastering PHP 7

Mastering PHP 7: Design, configure, build, and test professional web applications

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering PHP 7

Embracing Standards

Every profession and industry has its own set of standards. Whether formal or informal, they govern the way of doing things. The software industry tends to formalize standards into documents that establish various specifications and procedures designed to ensure the quality and reliability of products and services. They further incite the compatibility and interoperability processes, which otherwise might not be possible.

Putting the code into the context of products, various coding standards have emerged over the years. Their use yields greater code quality and reduced cognitive friction over our codebase. With code quality being one of the pillars of sustainable software development, it's no surprise standards are of impeccable importance to any professional developer.

When it comes to PHP, there are several layers of standards we need to take into consideration...

PSR-1 - basic coding standard

PSR-1 is the basic coding standard. It outlines the rules our code should follow, as seen by the members of PHP-FIG. The standard itself is quite short.

Files MUST use only <?php and <?= tags. At one time, PHP supported several different tags (<?php ?>, <? ?>, <?= ?>, <% %>, <%= %>, <script language="php"></script>). The use of some depend on the configuration directives short_open_tag (<? ?>) and asp_tags (<% %>, <%= %>). The PHP 7 release removed ASP tags (<%, <%=), and the script tag (<script language="php">) altogether. The use of only <?php ?> and <?= ?> tags is now recommended in order to maximize compatibility.

Files MUST use only UTF-8 without BOM for PHP code. The byte order mark (BOM) is a Unicode character, U+FEFF BYTE ORDER MARK...

PSR-2 - coding style guide

PSR-2 is an extension of PSR-1. This means that when talking about PSR-2, the PSR-1 standard is sort of implicitly understood. The difference is that PSR-2 expands beyond basic class and function formatting by enumerating a set of rules on how to format PHP code. The outlined style rules are derived shared similarities across the various PFP-FIG member projects.

Code MUST follow a coding style guide PSR (PSR-1). Goes to say that every PSR-2 code is implicitly PSR-1 compliant.

Code MUST use 4 spaces for indenting, not tabs. The spaces versus tabs dilemma is quite an old one in the programming world. There are those who the PHP-FIG group voted for the use of spaces, whereas 4 spaces represent what is usually a single tab indent. The benefit of a space over a tab is consistency. Whereas, a tab could show up as a different number of columns depending...

PSR-3 - logger interface

Logging different type of events is a common practice for applications. While one application might categorize these types of events into errors, informational events, and warnings, others might throw in more elaborate levels of severity logging. The same goes for the actual format of the log message itself. Goes to say that every application might easily have its own flavor of logging mechanism. This stands in a way of interoperability.

The PSR-3 standard sets out to fix this by defining a standard for the actual logger interface. Such a standardized interface then enables us to write PHP application logs in a simple and universal way.

The syslog protocol (RFC 5424), defined by Internet Engineering Task Force (IETF), differentiates the following eight severity levels:

  • emergency: This states the system is unusable
  • alert: This states action must be taken...

PSR-4 - autoloading standard

To this date, the PHP-FIG group has released two autoloading standards. Predating PSR-4 was PSR-0. It was the first standard released by the PHP-FIG group. Its class naming had certain backward compatibility features aligned with an even older PEAR standard. Whereas, each level of the hierarchy was separated with a single underscore, indicating pseudo-namespaces and directory structure. The PHP 5.3 release then brought official namespace support to the language. PSR-0 allowed both the old PEAR underscore mode and the use of the new namespace notation. Allowing the underscores for some time to follow eased the transition to namespaces and encouraged wider adoption. Pretty soon, Composer came on the scene.

Composer is a popular dependency manager for PHP that deals with packages and libraries by installing them in a vendor/ directory of our project.
...

PSR-6 - caching interface

Performance issues are the ever-hot topic of application development. The effects of poorly performing applications can sometimes have serious financial impact. Back in 2007, Amazon reported a 100 ms increase in https://www.amazon.com/ load time and their sales decreased by 1%. Several studies have also shown that nearly half of the users are likely to abandon the website if the page load time is over 3 seconds. To address the performance issues, we look into caching solutions.

Both browsers and servers allow caching of various resources, such as images, web pages, CSS/JS files. Sometimes, however, this is not enough as we need to be able to control the caching of various other bits on the application level, such as objects themselves. Over time, various libraries rolled out their own caching solutions. This made it tough for developers, as...

PSR-1 - basic coding standard


PSR-1 is the basic coding standard. It outlines the rules our code should follow, as seen by the members of PHP-FIG. The standard itself is quite short.

Files MUST use only <?php and <?= tags. At one time, PHP supported several different tags (<?php ?>, <? ?>, <?= ?>, <% %>, <%= %>, <script language="php"></script>). The use of some depend on the configuration directives short_open_tag (<? ?>) and asp_tags (<% %>, <%= %>). The PHP 7 release removed ASP tags (<%, <%=), and the script tag (<script language="php">) altogether. The use of only <?php ?> and <?= ?> tags is now recommended in order to maximize compatibility.

Files MUST use only UTF-8 without BOM for PHP code. The byte order mark (BOM) is a Unicode character, U+FEFF BYTE ORDER MARK (BOM), appearing at the beginning of a document. When used correctly, BOM is invisible. The HTML5 browsers are required to recognize...

PSR-2 - coding style guide


PSR-2 is an extension of PSR-1. This means that when talking about PSR-2, the PSR-1 standard is sort of implicitly understood. The difference is that PSR-2 expands beyond basic class and function formatting by enumerating a set of rules on how to format PHP code. The outlined style rules are derived shared similarities across the various PFP-FIG member projects.

Code MUST follow a coding style guide PSR (PSR-1). Goes to say that every PSR-2 code is implicitly PSR-1 compliant.

Code MUST use 4 spaces for indenting, not tabs. The spaces versus tabs dilemma is quite an old one in the programming world. There are those who the PHP-FIG group voted for the use of spaces, whereas 4 spaces represent what is usually a single tab indent. The benefit of a space over a tab is consistency. Whereas, a tab could show up as a different number of columns depending on the environment, a single space is always one column. While this might not be the most convincing argument of all,...

PSR-3 - logger interface


Logging different type of events is a common practice for applications. While one application might categorize these types of events into errors, informational events, and warnings, others might throw in more elaborate levels of severity logging. The same goes for the actual format of the log message itself. Goes to say that every application might easily have its own flavor of logging mechanism. This stands in a way of interoperability.

The PSR-3 standard sets out to fix this by defining a standard for the actual logger interface. Such a standardized interface then enables us to write PHP application logs in a simple and universal way.

The syslog protocol (RFC 5424), defined by Internet Engineering Task Force (IETF), differentiates the following eight severity levels:

  • emergency: This states the system is unusable
  • alert: This states action must be taken immediately
  • critical: This states critical conditions
  • error: This states error conditions
  • warning: This states warning...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Leverage the newest tools available in PHP 7 to build scalable applications
  • Embrace serverless architecture and the reactive programming paradigm, which are the latest additions to the PHP ecosystem
  • Explore dependency injection and implement design patterns to write elegant code

Description

PHP is a server-side scripting language that is widely used for web development. With this book, you will get a deep understanding of the advanced programming concepts in PHP and how to apply it practically The book starts by unveiling the new features of PHP 7 and walks you through several important standards set by PHP Framework Interop Group (PHP-FIG). You’ll see, in detail, the working of all magic methods, and the importance of effective PHP OOP concepts, which will enable you to write effective PHP code. You will find out how to implement design patterns and resolve dependencies to make your code base more elegant and readable. You will also build web services alongside microservices architecture, interact with databases, and work around third-party packages to enrich applications. This book delves into the details of PHP performance optimization. You will learn about serverless architecture and the reactive programming paradigm that found its way in the PHP ecosystem. The book also explores the best ways of testing your code, debugging, tracing, profiling, and deploying your PHP application. By the end of the book, you will be able to create readable, reliable, and robust applications in PHP to meet modern day requirements in the software industry.

Who is this book for?

This book is for intermediate level developers who want to become a master of PHP. Basic knowledge of PHP is required across areas such as basic syntax, types, variables, constants, expressions, operators, control structures, and functions.

What you will learn

  • Grasp the current state of PHP language and the PHP standards
  • Effectively implement logging and error handling during development
  • Build services through SOAP and REST and Apache Trift
  • Get to know the benefits of serverless architecture
  • Understand the basic principles of reactive programming to write asynchronous code
  • Practically implement several important design patterns
  • Write efficient code by executing dependency injection
  • See the working of all magic methods
  • Handle the command-line area tools and processes
  • Control the development process with proper debugging and profiling

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 27, 2017
Length: 536 pages
Edition : 1st
Language : English
ISBN-13 : 9781785889943
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 27, 2017
Length: 536 pages
Edition : 1st
Language : English
ISBN-13 : 9781785889943
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 110.97
PHP Microservices
€36.99
PHP 7 Data Structures and Algorithms
€36.99
Mastering PHP 7
€36.99
Total 110.97 Stars icon

Table of Contents

17 Chapters
The All New PHP Chevron down icon Chevron up icon
Embracing Standards Chevron down icon Chevron up icon
Error Handling and Logging Chevron down icon Chevron up icon
Magic Behind Magic Methods Chevron down icon Chevron up icon
The Realm of CLI Chevron down icon Chevron up icon
Prominent OOP Features Chevron down icon Chevron up icon
Optimizing for High Performance Chevron down icon Chevron up icon
Going Serverless Chevron down icon Chevron up icon
Reactive Programming Chevron down icon Chevron up icon
Common Design Patterns Chevron down icon Chevron up icon
Building Services Chevron down icon Chevron up icon
Working with Databases Chevron down icon Chevron up icon
Resolving Dependencies Chevron down icon Chevron up icon
Working with Packages Chevron down icon Chevron up icon
Testing the Important Bits Chevron down icon Chevron up icon
Debugging, Tracing, and Profiling Chevron down icon Chevron up icon
Hosting, Provisioning, and Deployment Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(7 Ratings)
5 star 85.7%
4 star 0%
3 star 14.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




mario a torre fuentelzas Dec 20, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Rapidez
Amazon Verified review Amazon
Maksym Jun 29, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book describes the new features of PHP 7.This is not a book that you can use to teach yourself PHP 'from scratch', so you should have knowledge of the previous PHP versions.
Amazon Verified review Amazon
Cliente de Amazon Jul 13, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the best books about PHP 7, contain very useful information, many topics in the book are just introductions but give you the vision of what subjects you need to dig more to be come a professional in PHP. If you already know how to code in PHP but want to be more proficient and know the technologies necessary for that, this book is for you.
Amazon Verified review Amazon
Vitor Adonai Arruda Barbosa Nov 10, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Esse livro é por tópicos, não existe um projeto final. Mas realmente, é bom!
Amazon Verified review Amazon
Lawrence Aug 19, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It is a good book. It goes over a verity of topics and really insightful.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.