Posts

Showing posts from June, 2021

From no framework to Symfony, Doctrine and dealing with migrations

 When I first started using Symfony, I had already developed a social media app  (github repository) through a Udemy Course  and while it made me get into the practice of PHP writing, I wondered quite a few things: 1. How am I supposed to remember this file structure in ten months time? Is there any kind of universal criteria that we are not following? 2. How the hell do developers find a bug in a file with 400 lines of PHP + HTML  3. How am I supposed to see the flow of the code? Obviously, as this is a guided programming course, questions were solved through subsequent videos or, through the course forum, but I still could not picture myself solving those bugs on my own. Moreover, as you will be able to see if you clicked on the github link (Developement branch) above mentioned, the mixture of languages along the files made me think that in order to be a developer you need to get a scanning app installed in your brain which would allow you to boost your reading in...

STUPID vs SOLID

 SOLID Principles were first collected by Robert C. Martin (also known as "uncle Bob"). It is the acronym for: S ingle Responsibility Open/Close Liskov Substitution Interface Segregation Dependency Inversion I will be talking about each of them in a series of Posts in this blog. But, let's talk first about the STUPID principles (believe it or not, this is also an acronym), opposite to this set of good practices, that we should avoid: Singleton A Singleton is a software design pattern  that restricts the instantiation of a class to one single object. This is useful when exactly one object is necessary to coordinate actions across the system. That is what theory says, but it's difficult to think of many situations which would require you to model an object with a singleton. It is, in fact, referred to as an anti-pattern. The main reason for this to be avoided is that it involves a high level of coupling, when we are in fact looking for the oppositte: low coupling and h...

Inheritance: Abstract classes and interfaces

What is inheritance? It's a programming principle used in the PHP object model which allows a class (child) to inherit another class' (parent) protected or public methods, properties and constants, retaining the parent's original functionality, unless these are overriden by the child class. What is an abstract class? A class that contains at least one abstract method, which means only the signature of the method is defined. For example: abstract Class Parent { abstract protected function defineMyFunction (). } Class Child extends Parent {      protected function defineMyFunction () {           return "I am an abstract function in my Parent class" ;      } } As childish as this example might seem , it quite easily represents the aforementioned definition. When a  class (or child class) extends from an abstract class (or parent class), it must define all methods declared as abstract. In fact, if you are using an IDE...

Differences between static properties and constants

Static properties are properties linked to the class and not a particular object, which means they can be accessed without instantiating them.  It is possible to reference static properties with a variable: class Parent { public static $static_property; } Static methods are called using the Scope Resolution Operator (::) . Inside of the class we would call it with self:: class Parent{ public static $static_property;      public function returnStaticPropertyValue() {      self::$static_property;                } } Outside of the class we would call it with the name of the class class Child { $child_inherited_static_property = Parent::$static_property; } Constants are an identifier for a simple value. For example, the value of number π of or the value of the garvity. They are declared starting with an underscore or letter, in capitals, without the $ sign or using the method  define() as follows. cl...