Re: Re: bug of the day: $this
| From: | Balazs Nagy | Date: | Sat, 07 Dec 2002 10:35:04 +0000 |
| Subject: | Re: Re: bug of the day: $this | ||
| References: | 1 2 3 4 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-92181@lists.php.net to get a copy of this message | ||
On Fri, 2002-12-06 at 22:11, Stig S. Bakken wrote:
> It won't be different in ZE2. This is not a bug though, but a tricky
> design issue. The problem is figuring out at runtime when to set $this
> or not in a method. What most people would probably find intuitive, is
> that $this was set only in methods called in the object, but this would
> require pretty expensive checks for every method call.
Maybe the roots of OO is my problem. PHP does similar, but not exactly.
I don't know whether you like clear things, or is this clear to you, but
I see confusion about handling $this. Excerpt from the documentation:
http://www.php.net/manual/en/language.oop.php
Within a class definition, you do not know under which name the object
will be accessible in your program: at the time the Cart class was
written, it was unknown that the object will be named $cart or
$another_cart later. Thus, you cannot write $cart->items within the Cart
class itself. Instead, in order to be able to access it's own functions
and variables from within a class, one can use the pseudo-variable $this
which can be read as 'my own' or 'current object'. Thus,
'$this->items[$artnr] += $num' can be read as 'add $num to the $artnr
counter of my own items array' or 'add $num to the $artnr counter of the
items array within the current object'.
> Andi can shed more light on this if needed.
Andi, please tell me why.
--
jul