A public static method is also called a “class method”.
The ... operator (a.k.a. “splat” in other languages) allows accepting a variable number of arguments, which are accessible as an array. It was introduced in PHP 5.6.
The extends keyword defines a child class, expressing a “is-a” relationship with the parent class.
Creating a child class is called “subclassing”.
The use keyword, in addition to being related to namespaces, also has another meaning in closures, making variables from the parent scope visible inside a lambda function.
array_map runs a callback against each item of an array, returning a new array.
array_column selects a property of each item of an array, returning a new array.
array_sum sums all items in a (numeric) array.
class_basename() is a Laravel helper function that returns the name of the actual class (i.e. if a subclass is instantiated, code in the parent class can use this method to know the name of the child class that the object was instantiated from).
Child classes can override parent members which have public or protectedvisibility.
Being a dynamic language, PHP supports “duck typing”: If something walks like a duck and quacks like a duck, it probably is a duck. The disadvantage is that IDEs cannot provide type checking and the code becomes less robust.
The interface keyword defines an interface.
Think of an interface as a class without behavior - only method signatures.
The implements keyword declares that a class implements an interface.
Think of “duck typing” as a handshake and of interfaces like formal contracts.
Both methods and properties can have a visibility (public/protected/private) assigned.
The default visibility is public (e.g. var and public have the same meaning).
Sometimes you have to make something public because it needs to be accessible by another part of your application, even though you don’t want to expose the functionality to third-party consumers of your API. In such cases developers often tag (annotate) the methods intended for third parties with @api or similar.
A value object protects simpler types (e.g., integers, strings, etc.) from being set to values that are invalid in the specific context.
To modify the values in a value object, create a new instance, add methods to make the values mutable, or add methods that return a new instance with the desired values.
Another use case for value objects is to group properties that belong together, such as the x and y of a set of coordinates, or the currency and the numeric value for an amount of money.