扫码阅读
手机扫码阅读

PHP高级编程-回归原生态-空与非空

45 2024-07-04
Chapter 4: Returning to Native PHP

Chapter 4: Returning to Native PHP

Despite the current trend, PHP remains a dominant language for web development. Its simplicity and ease of learning, alongside the contribution from the open-source community in terms of frameworks, libraries, and projects, make it highly accessible. These resources can be downloaded and used with minimal configuration, often without the need for further development.

However, it's crucial not to neglect native PHP. Understanding the underpinnings of PHP enables developers to grasp the intricacies of the classes, functions, modules, and extensions created by others. This depth of knowledge is especially critical for the development of medium to large projects. The details and differences of native PHP usage will be discussed further in subsequent sections.

Although PHP is easy to start with, mastering it is challenging and requires time and effort. This chapter won't cover all aspects of PHP but will highlight common and representative points to encourage a deeper understanding of native PHP among developers.

4.1 Emptiness and Non-Emptiness

Basic PHP syntax is easily recognizable, but subtleties can often be overlooked, particularly when combined with complex business logic and dispersed across thousands of lines of code. Recognizing these nuances quickly within a large codebase is a significant challenge.

4.1.1 Simple Emptiness Check

One of the most frequently used PHP functions is empty(). It's well-known which values are considered empty. According to the official documentation, the following are considered empty:

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • $var; (a declared variable without a value)

It is evident that under these conditions, the output of the empty() function will be true.

想要了解更多,点击 查看原文