#30423 [Opn]: get_class(self) for static methods

From: Date: Thu, 14 Oct 2004 01:23:37 +0000
Subject: #30423 [Opn]: get_class(self) for static methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67561@lists.php.net to get a copy of this message
 ID:               30423
 User updated by:  auroraeosrose at hotmail dot com
 Reported By:      auroraeosrose at hotmail dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.*
 New Comment:

oops, here are the results of my little test

Hello, I'm whoami 1 !
Value of __CLASS__ : test
Value of get_class($this) : test

Value of get_class() : test

Hello, I'm whoami 1 !
Value of __CLASS__ : test
Value of get_class($this) : test2

Value of get_class() : test


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

[2004-10-14 03:22:31] auroraeosrose at hotmail dot com

only problem is, get_class() returns what __CLASS__ returns, the actual
class your in, which is nice unless you need to know the class CALLED
not the PARENT

extremely simplistic view:

class test {
   function whoami() {
     echo "Hello, I'm whoami 1 !\r\n";
     echo "Value of __CLASS__ : ".__CLASS__."\r\n";
     echo "Value of get_class(\$this) : ".get_class($this)."\r\n\r\n";
     echo "Value of get_class() : ".get_class()."\r\n\r\n";
   }
  }
  class test2 extends test {
  }
  $test=new test;
  $test->whoami();
  $test2=new test2;
  $test2->whoami();

Now, you'll notice that get_class() is always returning the class
whoami is in - test, whereas get_class($this) is returning the CHILD
class, test2 - bug or feature? in any case it makes using get_class()
as useless for me as __CLASS__ , I need to know the class called, not
the class the function is in!

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

[2004-10-13 23:09:14] helly@php.net

Simply use get_class()

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

[2004-10-13 20:18:43] auroraeosrose at hotmail dot com

Description:
------------
When using parent - child classes you sometimes need to get the name of
the child, not the parent FROM the parent class.  In a regular object
instance you can do get_class($this);  However in static methods, you
cannot.  I'd really like a get_class(self); so that you can get the
same functionality in a static method.



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


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


Thread (13 messages)

« previous php.bugs (#67561) next »