That's pretty much it. Scoping in most OO programming languages resolves symbols fine without an explicit reference to the current instance (i.e. '$this' in PHP). Why does PHP require me to precede every call to a member function in the same class with $this?
views:
182answers:
1
+8
A:
To resolve the scope of the function call. Consider:
$this->strstr(...
and just
strstr(...
The latter will call PHP's built-in strstr() function which is not what we want to do here.
It's a consequence of adding OOP features to a high level procedural/scripting language.
karim79
2009-06-26 18:46:54
Makes sense. I feel that it's unnecessarily verbose to have to use $this->myFunc() all the time. However, in the case of PHP's built-in functions, you've got a point. If the '$this' qualifier weren't required, there would have to be a symbol that explicitly meant 'call the built-in method' (e.g. something like '$->ststr()'). Thanks for the answer. :)
2009-06-26 19:23:22
Although it would have been perfectly possible to have the function/method call resolved like e.g. C++ does. ::strstr()
VolkerK
2009-06-26 20:26:11