Monthly Archives: September 2022

OPERATORS IN PHP SECOND PART

OPERATORS IN PHP PRECEDENCE AMONG OPERATORS The precedence of an operator specifies how "tightly" it binds two expressions together. For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication operator ("*") has a higher precedence than the addition operator ("+"). Parentheses can be used to force precedence if necessary. For example: (1 + 5) * 3 returns 18. When operators have equal precedence, their associativity decides how to group the operators. For example, "-" is associative on the left, so 1 - 2 - 3 is grouped as (1 [...]

By |2024-08-29T23:16:46+02:001 September 2022|0 Comments

CONDITIONAL STRUCTURES AND LOOPS IN PHP

THE IF-ELSE STRUCTURE It is a very important structure that we will use often because based on one or more conditions we decide the flow of program execution. SUMMARY if(condition(s)){ //inside the block we put the instructions in case the condition is verified }else if (condition(s)){ //else if (otherwise if) is not mandatory. We can put as many ifs as we need. } else { //In all other cases.... } SAMPLE CODE <?php //IF ELSE //sintassi /*if(condizione/i){ all'interno del blocco mettiamo le istruzioni nel caso in cui la condizione è verificata }else if (condizione/i){ else if [...]

By |2022-09-23T01:12:17+02:005 September 2022|0 Comments

PHP FUNCTIONS FIRST PART

THE FUNCTIONS IN PHP DECLARATION OF A FUNCTION You define a function with the keyword function and a meaningful name. It is not good to give names that do not identify the function performed by the algorithm. If we want the instructions inside a function to be executed we must, as they say, invoke it . Even if we place the call before the definition, we have no error, the code is parsed beforehand and the functions are put in memory. In PHP we can define anonymous functions . what we can do with such functions is assign it [...]

By |2024-09-01T00:30:12+02:008 September 2022|0 Comments

THE FUNCTIONS IN PHP SECOND PART

THE FUNCTIONS IN PHP FUNCTIONS AS A LEVEL OF ABSTRACTION Suppose we want to define three sequences as shown in the code below. This code in general could be fine, only that every time we want to get this functionality we have to rewrite the low-level code. But we can create a level of abstraction thanks to functions. showSequence abstracts the 3 previously created loops. We create a library and bring the function into lib.php. We achieved the same result by adding a level of abstraction and the resulting code is much cleaner. [...]

By |2024-09-01T07:27:27+02:009 September 2022|0 Comments

OOP IN PHP FIRST PART

OBJECT ORIENTED PROGRAMMING IN PHP The first step in understanding OOP is to understand classes and objects. A class is a template of code used to create one or more objects. Imagine the prototype of a car, just as cars (objects) are created from the prototype (class), so in OOP from classes are created objects that can be, most often are, distinct from each other. A class is defined by the keyword class, it can contain letters and numbers but cannot begin with a number. The notation for class names is pascal-case (Like camel-case only the first letter is [...]

By |2024-09-02T19:59:30+02:0015 September 2022|0 Comments

OOP IN PHP SECOND PART

EXTENDING A CLASS INTRODUCTION The Course class is the class we use to create backend or frontend courses. We may use specialized public methods and properties for Frontend and Backend courses to make the class more useful. First this way of developing software implies that the Course class will grow very quickly, second if we create an object for the Frontend that object will be able to access methods and properties that are not necessary. The biggest problem is that we are mixing properties and methods specific to the Backend and Frontend courses. THE BACKEND AND FRONTEND CLASSES We [...]

By |2024-09-05T19:49:23+02:0017 September 2022|0 Comments

OOP IN PHP THIRD PARTY

TYPE HINTING ON OBJECTS Let's see with an image how it is possible to do type hinting to the summary method of the corso class. THE STATISTICS CLASS When we talked about functions, we also studied the type hinting scalar, the scalar values in PHP are booleans, integers floats and strings. Regarding the summarize method by returning a string, it would be appropriate to do type hinting as shown in the figure above. Since PHP version five we have type hinting on classes. Let's create a file Statistics.php inside the lib folder. In this case, the [...]

By |2024-09-09T03:17:25+02:0022 September 2022|0 Comments

OOP IN PHP FOURTH PART

OOP IN PHP FOURTH PART THE KEYWORD $ THIS, SELF, PARENT AND STATIC Initially it is not easy to find your way around, so let's make a brief summary. With the keyword $this we have a reference to the created instance, and we use it inside the classes to access non-static properties and methods, that is, that are specific to objects . Static methods and properties belong to the class and are outside the scope of instances. With the keyword self we have a reference to the class itself and we use it to access static properties and methods [...]

By |2024-09-10T05:50:24+02:0028 September 2022|0 Comments
Go to Top