PHP 7 Programming Cookbook cover

PHP 7 Programming Cookbook

No rating yet
Chapters
40
ISBN
9787121327728

Tags

Summary

PHP 7 Programming Cookbook is the Chinese translation of Doug Bierer's PHP 7 Programming Cookbook, translated by Su Baolong and published by Publishing House of Electronics Industry in October 2017. The book consists of 13 chapters and one appendix, and its basic premise is "learn PHP 7 through tasks": each chapter is built around a set of practical, implementable requirements, first clarifying the approach and then giving code recipes you can reproduce directly, rather than merely listing syntax as a manual would. It starts with setting up a development environment, covering key points for installing PHP 7, the built-in web server, and configuring a MySQL database for testing and PHPUnit, then implements class autoloading, a website scanner, and a simple web scraping tool; it then goes deeper into PHP 7's efficiency improvements, including the abstract syntax tree and differences in foreach processing, iterating over large data files, importing spreadsheets into a database, and a recursive directory iterator. The middle section covers functional programming (type hints, return types, iterators, and generators), object-oriented programming (namespaces, interfaces, traits, anonymous classes), and PDO database access, pagination, entity class mapping, and query integration with jQuery DataTables. The latter half turns to engineering capabilities: form element generators and form factories, $_POST filtering and validation, REST and SOAP clients and servers, date/time and internationalization (number, currency, and date formatting, internationalized calendars, and recurring event generation), PSR-7-based middleware (validation, access control, caching, routing, and framework interoperability), advanced algorithms such as linked lists, bubble sort, stacks, and binary search, and design patterns such as hydrators, strategy, mapper, and publish/subscribe. The final two chapters focus on web security (session protection, tokens, password generation, CAPTCHA, encryption and decryption) and on best practices, testing, and debugging, while the appendix implements PSR-7 value object classes, request classes, and response classes item by item. At about 577 pages, the book is dense and well suited as a desktop reference for intermediate and advanced developers to fill gaps and experiment hands-on.

Editor's review

这本书最讨喜的地方在于“问题驱动”。它没有从变量类型讲起,而是直接抛出一个需求——做个网站扫描器、把电子表格灌进数据库、给表单加验证与令牌、写个 REST 服务、搭一套路由中间件——然后给你一条能跑通的路。13 章依次覆盖环境与工具、PHP 7 效率特性、函数式与面向对象、数据库、表单与可伸缩页面、Web 服务、国际化、中间件、算法、设计模式、安全、测试调试,章节之间互相引用,像一条完整的工程链路。 对 2017 年的读者而言,PHP 7 带来的性能提升与语法现代化(标量类型提示、返回值类型、匿名类、生成器)正是升级动力,书中对这些点做了集中梳理,还单独讨论 PHP 5 代码迁移与 AST 带来的解析差异,实用性很强。附录逐行实现 PSR-7 值对象、请求与响应类,是把规范读薄的好材料;安全性一章把会话劫持、CSRF 令牌、密码存储、验证码和加密解密放在一起讲,思路比零散教程清晰。 需要提醒的是,书中示例基于当年的 PHP 7.0/7.1 与 mcrypt 时代,如今 PHP 8 已普及、mcrypt 被移除、PDO 与安全实践也有更新,代码需要读者自行适配。把它当作“PHP 工程技巧索引”而非最新版手册来读,收获最大:每一节都可以拆出来单独实验,尤其适合已有语法基础、想在项目里补齐国际化、中间件和测试能力的中级开发者。

Who it's for

A good fit for

  • 已掌握 PHP 基础语法、希望系统补齐面向对象与工程能力的中级开发者
  • 需要在项目中落地表单验证、REST/SOAP 接口、路由与中间件的前后端工程师
  • 想了解设计模式、算法基础与 Web 安全防护如何落在 PHP 代码里的技术人员
  • 从 PHP 5 升级到 PHP 7 后,希望理解语言新特性差异与迁移要点的维护者
  • 希望借 PSR-7 实现理解 PSR 规范与框架互操作原理的架构学习者

Not a good fit for

  • 完全零基础、连变量、循环和 HTTP 请求都还不熟悉的编程新手
  • 只想要一本与当前 PHP 8.x 最新特性完全同步的版本手册的读者
  • 期待系统讲解前端框架、数据库运维或服务器部署的内容的运维与前端读者

Reading tips

  1. 先按第1章把 PHP 7、MySQL、PHPUnit 与自动加载环境搭起来,后续示例才能连贯跑通
  2. 把每章当作独立任务清单,边读边敲代码并提交到版本库,形成自己的代码片段库
  3. 阅读数据库、表单、Web 服务、中间件四章时,尝试把示例改造成自己项目中的一个小模块
  4. 注意版本差异:mcrypt、部分 PDO 与安全写法在 PHP 8 中已变化,动手前先查阅现行官方文档

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Chapter 1: Fundamentals
  2. Notes on Installing PHP 7
  3. Using the Built-in PHP Web Server
  4. Defining a MySQL Database for Testing / Installing PHPUnit / Implementing Class Autoloading
  5. Scanning a Website / Creating a Deep Web Scanner / Creating a Code Converter from PHP 5 to PHP 7
  6. Chapter 2: Effective Features in PHP 7
  7. Understanding the Abstract Syntax Tree / Understanding Differences in Parsing / Understanding Differences in foreach() Processing
  8. Using PHP 7 Enhancements to Improve Performance
  9. Iterating Over Files with Large Amounts of Data / Uploading Spreadsheets to a Database / Recursive Directory Iterator
  10. Chapter 3: Functional Programming Features in PHP
  11. Developing Functions / Hinting Data Types / Setting the Return Data Type of Functions
  12. Using Iterators / Writing Your Own Iterators with Generators
  13. Chapter 4: Object-Oriented Programming Features in PHP
  14. Developing Classes / Extending Classes / Using Static Properties and Methods / Using Namespaces
  15. Defining Visibility / Using Interfaces / Using Traits / Implementing Anonymous Classes
  16. Chapter 5: Interacting with Databases
  17. Connecting to a Database with PDO / Creating an OOP-Style SQL Statement Builder / Handling Pagination
  18. Defining Entities That Match Database Tables / Setting Entity Class Data Types to Match RDBMS Query Operations
  19. Embedding Secondary Queries in Query Results / Implementing PHP Queries for the jQuery DataTables Plugin
  20. Chapter 6: Creating Scalable Websites
  21. Creating a Generic Form Element Generator / Creating an HTML Radio Element Generator / Creating an HTML Select Element Generator
  22. Implementing a Form Factory / Associating $_POST Filters / Associating $_POST Validators / Associating Validation with Forms
  23. Chapter 7: Accessing Web Services
  24. Converting Between PHP and XML
  25. Creating a Simple REST Client / Creating a Simple REST Server
  26. Creating a Simple SOAP Client / Creating a Simple SOAP Server
  27. Chapter 8: Using date/time Data Types and Internationalization Features
  28. Using Emoticons or Emoji in View Scripts / Converting Complex Characters / Getting User Location from Browser Data
  29. Displaying Numbers in Appropriate Formats for the User's Location / Handling Currency Data / Formatting date/time Data Types
  30. Creating an HTML-Style Internationalized Calendar Generator / Creating a Recurring Event Generator
  31. Handling Translation Work Without the gettext Toolset
  32. Chapter 9: Developing Middleware
  33. Performing Validation Through Middleware / Implementing Access Control with Middleware / Improving Performance with Caching
  34. Implementing Routing / Implementing Interoperability Between Framework Systems / Implementing Cross-Language Functionality with Middleware
  35. Chapter 10: Advanced Algorithms
  36. Using Getters and Setters / Implementing a Linked List / Writing a Bubble Sort Program
  37. Implementing a Stack / Creating a Class That Implements Binary Search / Implementing a Search Engine / Displaying Multidimensional Arrays and Cumulative Totals
  38. Chapter 11: Implementing Various Software Design Patterns
  39. Creating an Array-to-Object Hydrator / Creating an Object-to-Array Hydrator
  40. Implementing the Strategy Pattern / Defining a Mapper / Implementing Object-Relational Mapping / Implementing the Publish/Subscribe Design Pattern

FAQ

这本书的原版英文书名是什么?
英文原名为 PHP 7 Programming Cookbook,由 Packt Publishing 出版,中文简体版版权由 Packt 授予电子工业出版社,译者为苏宝龙。
书里的代码现在还能直接运行吗?
大部分思路与结构仍然有效,但示例基于 PHP 7.0/7.1 时期,mcrypt 扩展在新版 PHP 中已移除,PDO 选项与部分安全写法也有更新,运行前需按现行版本做适配。
零基础能直接读这本吗?
不太建议。书中默认读者熟悉 PHP 基本语法与 HTTP 概念,入门内容只集中在环境搭建部分,其余章节直接进入面向对象、数据库和中间件等中高级主题。
附录的 PSR-7 部分讲什么?
附录“定义 PSR-7 类”包含实现 PSR-7 值对象类、开发 PSR-7 请求类和定义 PSR-7 回应类三部分,通过手写实现帮助理解这一 HTTP 消息规范。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

More by the same author

Top rated in the same category