1
I am studying PHP and Python and I am feeling a huge difficulty, not in relation to concepts, after all they are independent of language, what is making hard the study is how PHP implements the manipulation of their objects, follows an example:
// Em PHP
>>> $frase = "Lorem ipsum";
>>> echo str_replace(" ", "<br/>", $frase); // "lorem<br/>ipsum"
# Em Python
>>> frase = "Lorem ipsum ...";
>>> print(frase.replace(" ", <br/>))
Whenever you start your studies in POO the information that repeats most is:
In object orientation, a class is a description that abstracts a set of objects with similar characteristics. More formally, it is a concept that encapsulates abstractions of data and procedures that describe the content and behaviour of real-world entities, represented by objects. Otherwise, a class can be defined as a description of the possible properties or states of a set of objects as well as the applicable behaviors or actions to these same objects.
So why while trying to access data on, for example files, arrays and others, or even modify their state I must use functions and not methods that in my view would make sense to be defined in a class and used as method.
I want to point out here that what I am saying may be wrong (after all if I was right I wouldn’t be asking), I would like you to address my doubts as to why the implementation of the two is so different.
Welcome to the world of programming! Inconsistencies like these are common, especially in PHP which is one of the most inconsistent languages!
– nosklo