PHP is a popular scripting language that can be embedded into HTML and other web languages. php developers are typically focused on php development, but may also manage the php codebase for an organization. In this blog post, we will discuss how to structure your php code so that it is readable and maintainable by others.
PHP code is typically structured as php classes. A php class is a template for an object that represents some real-world entity in the app, such as a user or product. php developers are responsible for creating these php classes and populating them with data before passing it off to other devs to work on the front end of the application (html/css).
The php developper has two options:
- pass it off directly in order to give specific instructions about how they want their php objects populated; or
- create documentation separate from your source code so others can understand what you were thinking when writing this particular part of the codebase. Both have benefits and drawbacks which will be discussed below.
Before we get into talking about php documentation, let's first discuss the php class itself and how to go about structuring it. A php developer should start by writing a description of what this php object actually represents in natural language (think english) so that other devs can understand its purpose without having to read through your code. Next you will want to list out all of the properties (variables/arrays) associated with this php object as well as any functions or methods which are required for manipulating these variables/arrays.
This is where many developers become discouraged when they see just how much boilerplate needs to be written before even getting into some actual functionality since their objects typically have hundreds of properties! But do not despair: there are ways around this.