ID:               33361
 User updated by:  halmai at nexum dot hu
 Reported By:      halmai at nexum dot hu
-Status:           Bogus
+Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Linux
 PHP Version:      4.3.10
 New Comment:

Sorry, I forgot to reopen the state of this report.


Previous Comments:
------------------------------------------------------------------------

[2005-06-16 13:39:24] halmai at nexum dot hu

I know that this is not a bug. This is a feature, but a really silly
and useless feature.

That's why I reported it as a "feature/change request".

------------------------------------------------------------------------

[2005-06-16 13:28:24] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

. 

------------------------------------------------------------------------

[2005-06-16 13:14:55] halmai at nexum dot hu

Description:
------------
I have two classes with one function respectively. 

In any function the variable $this should mean 
- the instance of the class if this function was called as a function
of an instance of _that_ class, and 
- it should be undefined (null) if called as a static function.

My problem is that if I call a static function of a class A from a
non-static function of class B then in the member function of class A
the variable $this denotes the instance of the class B instead of being
null.

The fact that in a function of class A the variable $this denotes an
instance of class B is really confusing. If it was called statically
then $this should be null. 

I know that this is described as normal behaviour but I think this is a
useless and senseless feature. In case of accepting my suggestion it
would be easy to decide whether a function was called in a static or
non-static context.

Reproduce code:
---------------
class A {
  function what_am_i() {
    if ( $this === null ) {
      print "i am not an instance<br>";
    } else {
      print "i am an instance from the class '".get_class( $this
)."'.<br>";
    }
  }
}
class B {
  function wrapper() {
    A::what_am_i();  
  }
}
A::what_am_i(); // i am not an instance (this is OK)
$a = new A();
$a -> what_am_i(); // i am an instance from the class 'a'. (this is
OK)

$b = new B();
$b -> wrapper();  // i am an instance from the class 'b'. (this should
output not an instance)


Expected result:
----------------
i am not an instance
i am an instance from the class 'a'.
i am not an instance


Actual result:
--------------
i am not an instance
i am an instance from the class 'a'.
i am an instance from the class 'b'.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33361&edit=1

Reply via email to