Object orientation (OO) is something that was tacked on to PHP "after the fact". Before OO was implemented everything was done using functions (like many other C-like programming languages).
When it comes to PHP, strings, integers, booleans, etc. are just data. They are primitive types and cannot do anything; they are just named values stored in memory. This is why you need to use functions, like strlen($str)
. The function operates on the value.
In languages like Ruby and Javascript most data types, such as strings, are, practically speaking, actually objects (or in some cases kinda-sorta objects). They contain various properties like .length
, and methods like .indexOf()
. Another word for such data types is a composite type (they are composed of more than one thing).
So, in PHP you can say that it is normal to write strlen($str)
to figure out how long a string is; likewise, in Javascript or Ruby it is normal to write str.length
.
It is possible to write a String
class in PHP, but it is kind of beside the point. It is like learning to count to ten, but insisting that it be done in base-7. It is not very practical, and people will think you are crazy.