Req #41856 [Opn->Wfx]: support for anonymous classes

From: Date: Sun, 02 Nov 2014 00:52:46 +0000
Subject: Req #41856 [Opn->Wfx]: support for anonymous classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188413@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=41856&edit=1

 ID:                 41856
 Updated by:         requinix@php.net
 Reported by:        mbaynton at gmail dot com
 Summary:            support for anonymous classes
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            *General Issues
 PHP Version:        5.2.3
 Block user comment: N
 Private report:     N

 New Comment:

anonymous_classes was declined.


Previous Comments:
------------------------------------------------------------------------
[2013-09-22 17:15:16] krakjoe@php.net

http://wiki.php.net/rfc/anonymous_classes

------------------------------------------------------------------------
[2013-09-02 22:06:30] johannes@php.net

My guess is that anonymous classes would have a good chance once a good implementation comes by.
This is not completely trivial as the class_entry has to be stored in the class_table but has to be
somewhat hidden and we might have to find a way to hide the information in the oparray.

As all things in PHP this needs a volunteer to do it. All contributors have sometime X to work on
PHP and in time X can either discuss stuff, fix bugs or implement features ... but with some
guidance this might be a nice project for a newcomer (I'd volunteer to give a hand to point in
the right direction etc., while  this guarantees acceptance in no way as that would need an RFC
etc.) until then we have to live with workarounds.

For the PageController interface example an (work-around) alternative is

$page_controller = [
  'get'  => function () {},
  'post' => function () {}
};

------------------------------------------------------------------------
[2013-09-02 21:42:36] zatacorothx at gmail dot com

Anonymous classes in Java are convenient when used with Interfaces. In PHP, this 
could help with MVC frameworks. Say all pages had a class that implemented 
PageController:
[some_page.php]
$page_controller = new PageInterface() {
  function doGet() {}
  function doPost() {}
};

A current workaround would be using a factory or constructor to which you pass 
required methods, and not using an interface. It works, but then you have to 
deal with missing methods in application logic where you could otherwise just 
handle an error.

------------------------------------------------------------------------
[2013-07-22 15:32:27] pacerier at gmail dot com

+1

------------------------------------------------------------------------
[2012-03-15 18:45:47] pajoye@php.net

Not exactly the same but look at closure and traits support in 5.4.

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


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=41856


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


Thread (14 messages)

« previous php.bugs (#188413) next »