Req #34804 [Opn->Csd]: More information about static class methods

From: Date: Sun, 16 Oct 2016 12:11:32 +0000
Subject: Req #34804 [Opn->Csd]: More information about static class methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204827@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=34804&edit=1

 ID:                 34804
 Updated by:         nikic@php.net
 Reported by:        toomuchphp-phpbugs at yahoo dot com
 Summary:            More information about static class methods
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Any
 PHP Version:        5.x
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

This should be resolved as of PHP 5.3 with get_called_class() or as of PHP 5.5 with static::class.


Previous Comments:
------------------------------------------------------------------------
[2011-07-14 09:33:30] nospam at attractive-nuisance dot net

__STATIC__

------------------------------------------------------------------------
[2007-07-13 20:57:49] public1 at fridaythe14th dot com

I agree that there needs to be some method of accessing the calling class. The current
implementation doesn't make sense and has no real world use. This is the thing that currently
annoys me the most with PHP.

I don't really care how this gets solved. If self, __CLASS__ and get_class() are sacred any new
constant or function would be appreciated.

------------------------------------------------------------------------
[2006-08-02 17:01:48] benjaminhill at gmail dot com

even something as simple as...

class Parent {
  static function myCurrentClassName() {
    return (__CALLINGCLASS__);
  }
}

class Child extends Parent {
  // empty
}

echo Child::myCurrentClassName() 
returns "Child"

------------------------------------------------------------------------
[2006-06-24 23:20:38] DouglasStewart at creighton dot edu

Understood toomuch, thanks.

I would then request the following:

Please provide the following on the static side:

$this -- in the context of a class side(static) method. $this represents an instance of
ReflectionClass with all methods answering correctly as to the context of the call. So, for
instance, statically implemented "$this->fileName()" would return the fileName that the
current context class was loaded from. With this feature in place, I am confident that self will no
longer be used for anything except in a root class like Object.

$sender -- Either a ReflectionClass instance when the call is made from a class-side implementation
or a regular object instance.

class() -- An instance method that all objects inherit, that returns an instance of ReflectionClass
for the class of the object context making the call.

Smalltalk offers some rather elegant solutions to these true OO problems that PHP's sudo-OO
implementation struggles with.

------------------------------------------------------------------------
[2006-06-19 23:44:53] toomuchphp-phpbugs at yahoo dot com

The reason why some of the bug reports get dismissed so easily is because they ask for one of the
existing features ('self' or '__CLASS__') to be modified to solve this problem,
but 'self' and '__CLASS__' are both already very useful and proably very widely
used, so it's not good to change them, and therefore we need a *new way* to find out what class
the static method was part of.

Something I find very disappointing is the fact that bug #30828 destroyed the only existing solution
to this problem - debug_backtrace().  In PHP 5.0.4, debug_backtrace() could have been used here to
discover the static class name, but somebody wanted it working the other way (like __CLASS__
instead), the bug was reported, fixed in 5.0.5, and so we lost our only solution to this problem. 
This bugfix actually broke some of my existing code a year ago when it was released, but it
wasn't so important to me at the time.  It's only over the past year as I've been
writing object-oriented code full time, and studying implementations by other languages (Java,
AspectJ, Ruby) that I've realized how damaging the change to debug_backtrace() was.

I am hoping that as Zend continue writing their Framework, they'll realize just how broken
static methods are and will try to fix them somehow.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=34804


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


Thread (10 messages)

« previous php.bugs (#204827) next »