Re: [PHP-DEV] Re: bug of the day: $this

2002-12-07 Thread Balazs Nagy
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

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-06 Thread George Schlossnagle
Why do the (cheap) checks implemented in debug_backtrace not work for 
this?

George

On Friday, December 6, 2002, at 04:11  PM, 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.

Andi can shed more light on this if needed.

 - Stig

On Wed, 2002-12-04 at 00:25, Markus Fischer wrote:

I think issue is/will be adressed in ZendEngine2 but I could
be wrong. I suggest inquiring at the engine2 list.

On Tue, Dec 03, 2002 at 08:53:25PM +, Ivan Ristic wrote :

Balazs Nagy wrote:

Hi,

$this stays defined when an instantatiated member function calls a
non-instantiated member function.


  Correct. I actually find it quite interesting. :)
  It can be useful at times, I have used it in my
  libraries as a feature.

  There is an interesting article on the subject:
  http://www.advogato.org/article/470.html


--
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-06 Thread Stig S. Bakken
On Wed, 2002-12-04 at 01:32, Balazs Nagy wrote:
> On Tue, 2002-12-03 at 21:53, Ivan Ristic wrote:
> > Balazs Nagy wrote:
> > > Hi,
> > > 
> > > $this stays defined when an instantatiated member function calls a
> > > non-instantiated member function.
> > 
> >Correct. I actually find it quite interesting. :)
> >It can be useful at times, I have used it in my
> >libraries as a feature.
> > 
> >There is an interesting article on the subject:
> >http://www.advogato.org/article/470.html
> 
> Now, please tell me how can you decide whether the member function is
> called as an object element (eg. $obj->func()) or as a class element
> (eg. class::func()).
> 
> Basic functionality is killed with this so-called feature.  The right
> way should be a call stack, with for example a $_STACK array, or through
> stack functions (eg. this_object(), previous_object()).

this_object()?  LPC? :)

 - Stig


-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-06 Thread Stig S. Bakken
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.

Andi can shed more light on this if needed.

 - Stig

On Wed, 2002-12-04 at 00:25, Markus Fischer wrote:
> I think issue is/will be adressed in ZendEngine2 but I could
> be wrong. I suggest inquiring at the engine2 list.
> 
> On Tue, Dec 03, 2002 at 08:53:25PM +, Ivan Ristic wrote : 
> > Balazs Nagy wrote:
> > >Hi,
> > >
> > >$this stays defined when an instantatiated member function calls a
> > >non-instantiated member function.
> > 
> >   Correct. I actually find it quite interesting. :)
> >   It can be useful at times, I have used it in my
> >   libraries as a feature.
> > 
> >   There is an interesting article on the subject:
> >   http://www.advogato.org/article/470.html

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-03 Thread Ivan Ristic


$this stays defined when an instantatiated member function calls a
non-instantiated member function.


  Correct. I actually find it quite interesting. :)
  It can be useful at times, I have used it in my
  libraries as a feature.

  There is an interesting article on the subject:
  http://www.advogato.org/article/470.html



Now, please tell me how can you decide whether the member function is
called as an object element (eg. $obj->func()) or as a class element
(eg. class::func()).


  You mean from the function itself? You can't, as far as I
  can tell. That is why this works best if you have a "helper"
  class with all static methods. Once nice example that
  comes to mind is a method that persists objects to the
  database.

  But never mind that, I am not trying to justify the
  existence of this quirk so there is no point in
  discussing it.



Basic functionality is killed with this so-called feature.


  Although I did use it as such, I wouldn't actually call
  this a feature, and would prefer to have it removed from
  ZE2.


Bye,
Ivan


--
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-03 Thread Balazs Nagy
On Tue, 2002-12-03 at 21:53, Ivan Ristic wrote:
> Balazs Nagy wrote:
> > Hi,
> > 
> > $this stays defined when an instantatiated member function calls a
> > non-instantiated member function.
> 
>Correct. I actually find it quite interesting. :)
>It can be useful at times, I have used it in my
>libraries as a feature.
> 
>There is an interesting article on the subject:
>http://www.advogato.org/article/470.html

Now, please tell me how can you decide whether the member function is
called as an object element (eg. $obj->func()) or as a class element
(eg. class::func()).

Basic functionality is killed with this so-called feature.  The right
way should be a call stack, with for example a $_STACK array, or through
stack functions (eg. this_object(), previous_object()).
-- 
jul

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Re: bug of the day: $this

2002-12-03 Thread Markus Fischer
I think issue is/will be adressed in ZendEngine2 but I could
be wrong. I suggest inquiring at the engine2 list.

On Tue, Dec 03, 2002 at 08:53:25PM +, Ivan Ristic wrote : 
> Balazs Nagy wrote:
> >Hi,
> >
> >$this stays defined when an instantatiated member function calls a
> >non-instantiated member function.
> 
>   Correct. I actually find it quite interesting. :)
>   It can be useful at times, I have used it in my
>   libraries as a feature.
> 
>   There is an interesting article on the subject:
>   http://www.advogato.org/article/470.html

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] Re: bug of the day: $this

2002-12-03 Thread Ivan Ristic
Balazs Nagy wrote:

Hi,

$this stays defined when an instantatiated member function calls a
non-instantiated member function.


  Correct. I actually find it quite interesting. :)
  It can be useful at times, I have used it in my
  libraries as a feature.

  There is an interesting article on the subject:
  http://www.advogato.org/article/470.html

--
Ivan Ristic, http://www.webkreator.com


--
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php