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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PHP 7 Programming Cookbook

You're reading from   PHP 7 Programming Cookbook Over 80 recipes that will take your PHP 7 web development skills to the next level!

Arrow left icon
Product type Paperback
Published in Aug 2016
Publisher Packt
ISBN-13 9781785883446
Length 610 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Doug Bierer Doug Bierer
Author Profile Icon Doug Bierer
Doug Bierer
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Building a Foundation FREE CHAPTER 2. Using PHP 7 High Performance Features 3. Working with PHP Functional Programming 4. Working with PHP Object-Oriented Programming 5. Interacting with a Database 6. Building Scalable Websites 7. Accessing Web Services 8. Working with Date/Time and International Aspects 9. Developing Middleware 10. Looking at Advanced Algorithms 11. Implementing Software Design Patterns 12. Improving Web Security 13. Best Practices, Testing, and Debugging A. Defining PSR-7 Classes Index

What this book covers

Chapter 1, Building a Foundation, helps you get started with the initial setup and configuration of your PHP 7 development environment. We will also present a few hard-hitting initial recipes, which show off new features of PHP 7.

Chapter 2, Using PHP 7 High Performance Features, takes a deep dive into the new features of the language. You will be introduced to the concepts of the abstract syntax tree and uniform variable syntax, among others, and you will learn how these can affect day-to-day programming. This is followed by recipes that take advantage of PHP 7 performance improvements, including significant new changes in the foreach() loop handling.

Chapter 3, Working with PHP Functional Programming, emphasizes how PHP has always had the capability of working with programmer-defined libraries of functions rather than classes, and PHP 7 is no exception. In this chapter, we will take a closer look at improvements in the handling of functions, including the ability to provide "type hints" involving basic data types, such as integer, float, Boolean, and string for both input and output. We will also provide extensive coverage of iterators from the Standard PHP Library, as well as how to write your own iterators by taking advantage of improved handling of generators.

Chapter 4, Working with PHP Object-Oriented Programming, explores the basics of PHP object-oriented programming. Quickly getting beyond the basics, you will learn how to use PHP namespaces and traits. Architectural considerations will be covered, including how to best use interfaces. Finally, an exciting new PHP 7 feature, anonymous classes, will be discussed along with practical examples of its use.

Chapter 5, Interacting with a Database, explores the ability to have your application read from and write to a database, which is a critical part of any modern website. What is widely misunderstood, however, is the proper use of the PHP Data Objects (PDO) extension. This chapter will present thorough coverage of PDO, which in turn will allow your applications to interact with most major databases, including MySQL, Oracle, PostgreSQL, IBM DB2, and Microsoft SQL Server, without having to learn any other set of commands. In addition, we will cover advanced techniques, such as working with Domain Model Entities, performing embedded secondary lookups, and implementing jQuery DataTable lookups using PHP 7.

Chapter 6, Building Scalable Websites, delves into one of the classic problems faced by PHP developers building interactive websites—hardcoding HTML forms and later having to perform maintenance. A neat and efficient object-oriented approach is presented in this chapter, which, with a minimal amount of code, lets you generate entire HTML forms that can easily be changed in the initial configuration. Another equally vexing problem is how to filter and validate data posted from a form. In this chapter, you will learn how to develop an easily configurable filtering and validation factory, which can then be applied to any incoming post data.

Chapter 7, Accessing Web Services, covers something that is becoming more and more important to web development—the ability to publish or consume web services. This chapter covers the two key approaches: SOAP and REST. You will learn how to implement SOAP and REST servers and clients. Further more, the recipes presented use the Adapter design pattern, which allows a considerable degree of customization, meaning that you are not locked into a specific design paradigm.

Chapter 8, Working with Date/Time and International Aspects, helps you cope with the fierce competition owing to the growth of the World Wide Web (WWW), leading to more and more customers looking to expand their business into international markets. This chapter will get you up to speed on all aspects of internationalization, including the use of emoticons, complex characters, and translation. Further more, you will be shown how to acquire and handle regional information, including language settings, number and currency formatting, as well as date and time. Additionally, we will cover recipes that show you how to create internationalized calendars, which can handle recurring events.

Chapter 9, Developing Middleware, deals with the hottest topic in the open source community right now—middleware. As the name implies, middleware is software that can be snapped into place, which adds value to an existing application without having to alter the source code of that application. In this chapter, you will be shown a series of recipes, implemented as PSR-7-compliant middleware (see Appendix, Defining PSR-7 Classes, for more details), which perform authentication, access control, caching, and routing.

Chapter 10, Looking at Advanced Algorithms, helps you understand that, as a developer, given the tremendous number of programmers and companies competing for the same business, it is extremely important that you gain mastery of key advanced algorithms. In this chapter, using PHP 7, you will learn the theory and application of getters and setters, linked lists, bubble sorts, stacks, and binary search. In addition, this chapter examines how to use these techniques to implement a search engine, and how to handle multi-dimensional arrays.

Chapter 11, Implementing Software Design Patterns, works on an important aspect of object-oriented programming, that is, an understanding of key software design patterns. Without this knowledge, when applying for a new position or attempting to attract new customers, you, as a developer, will be at a severe disadvantage. This chapter covers several critically important patterns including Hydration, Strategy, Mapper, Object Relational Mapping, and Pub/Sub.

Chapter 12, Improving Web Security, addresses issues arising from the pervasive nature of the Internet today. We see cyber attacks being launched with greater and greater frequency, often with devastating financial and personal loss. In this chapter, we will present solid practical recipes that, if implemented, will give your websites an exponential boost in terms of safety and security. Topics covered include filtering and validation, session protection, secure form submission, secure password generation, and the use of CAPTCHAs. In addition, a recipe is presented that will show you how to encrypt and decrypt data without using the PHP mcrypt extension, which is deprecated in PHP 7.1 (and will ultimately be removed from the language).

Chapter 13, Best Practices, Testing, and Debugging, covers best practices and debugging of your code to produce well written code that works. In this chapter, you will also learn how to set up and create unit tests, handle unexpected errors and exceptions, and generate test data. Several new PHP 7 features are presented, including how PHP 7 can "throw" errors. It is important to note that best practices are identified throughout the book, not just in this chapter!

Appendix, Defining PSR-7 Classes, addresses recently accepted PHP Standards Recommendation 7, which defines interfaces used in conjunction with middleware. In this appendix, you will be shown solid implementations of PSR-7 classes that include value objects, such as URI, body, and file upload, as well as request and response objects.

lock icon The rest of the chapter is locked
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 $19.99/month. Cancel anytime
Banner background image