# [RFC] Anonymous Classes

- Thread: https://externals.io/message/83662
- Original archive: https://news-web.php.net/php.internals/83662
- Started by Philip Sturgeon on 2015-02-24T13:52:21+00:00
- Messages: 35
- RFC: Anonymous Class Support (Implemented (PHP 7.0)) — https://externals.io/rfc/anonymous_classes.md
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/83662.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #83662 — Philip Sturgeon — 2015-02-24T13:52:21+00:00

URL: https://externals.io/message/83662#83662

Good day!

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

There's a little RFC + patch that Joe Watkins put together, and as
before with the ArrayOf RFC, I'll be helping out.

So, lets get this discussion rolling.

It was declined for PHP 5 some time ago, and has returned now to try for PHP 7.

The usage of anonymous classes to some will be instantly offensive,
but really it comes down to the use case. The usage of anonymous
functions compared to declared functions is pretty much the exact same
thing as anonymous classes.

Other than examples on the RFC, Fractal would certainly be happy to
have them: http://fractal.thephpleague.com/transformers/

Defining a class properly is certainly still going to be the majority
of uses of classes in PHP. That helps with the Optimizer, and helps
code reuse.

Sadly due to the way in which people have had ONE CLASS ONE FILE
drilled into their head since PEAR and continuing through Zend and
PSR-0, it can become a PITA to add some simple functionality if a
small class is needed for one tiny thing.

Anonymous functions alleviate that annoyance with a simple and
consistent feature that just give people a nice simple option to get
their jobs done, without hitting autoloaders and file systems to do
it.

---

## #83664 — Dmitry Stogov — 2015-02-24T14:10:42+00:00

URL: https://externals.io/message/83662#83664 · In reply to: #83662

I think the proposal is a bit incomplete.
It's possible to instantiate an anonymous class, but currently it's not
possible to do with them anything else (assign to variable, pass to
function, etc). Something similar to Closure objects should be introduced.

Thanks. Dmitry.

On Tue, Feb 24, 2015 at 4:52 PM, Philip Sturgeon <pjsturgeon@gmail.com>
wrote:

> Good day!
>
> https://wiki.php.net/rfc/anonymous_classes
>
> There's a little RFC + patch that Joe Watkins put together, and as
> before with the ArrayOf RFC, I'll be helping out.
>
> So, lets get this discussion rolling.
>
> It was declined for PHP 5 some time ago, and has returned now to try for
> PHP 7.
>
> The usage of anonymous classes to some will be instantly offensive,
> but really it comes down to the use case. The usage of anonymous
> functions compared to declared functions is pretty much the exact same
> thing as anonymous classes.
>
> Other than examples on the RFC, Fractal would certainly be happy to
> have them: http://fractal.thephpleague.com/transformers/
>
> Defining a class properly is certainly still going to be the majority
> of uses of classes in PHP. That helps with the Optimizer, and helps
> code reuse.
>
> Sadly due to the way in which people have had ONE CLASS ONE FILE
> drilled into their head since PEAR and continuing through Zend and
> PSR-0, it can become a PITA to add some simple functionality if a
> small class is needed for one tiny thing.
>
> Anonymous functions alleviate that annoyance with a simple and
> consistent feature that just give people a nice simple option to get
> their jobs done, without hitting autoloaders and file systems to do
> it.

---

## #83665 — Philip Sturgeon — 2015-02-24T14:20:16+00:00

URL: https://externals.io/message/83662#83665 · In reply to: #83664

> I think the proposal is a bit incomplete.
> It's possible to instantiate an anonymous class, but currently it's not
> possible to do with them anything else (assign to variable, pass to
> function, etc). Something similar to Closure objects should be introduced.
>
> Thanks. Dmitry.
>
> On Tue, Feb 24, 2015 at 4:52 PM, Philip Sturgeon <pjsturgeon@gmail.com>
> wrote:

1. You can absolutely assign the instantiated classes to variables.

Check out this test in the patch:
https://github.com/krakjoe/php-src/compare/anon#diff-25e330fb5a98810de178a5b798102d01R1

2. Why do you say they cannot be passed to a function? I can add a
test if you can give me an example of what you're suggesting doesn't
work.

3. Not sure why we'd need a Closure-alike object. Anonymous classes
are just a class, and classes have all the types and hinting
functionality of regular classes. You don't need to implement a class
to let people know its a class.

Maybe you could expand on that a bit? :)

---

## #83666 — Dennis Birkholz — 2015-02-24T14:29:17+00:00

URL: https://externals.io/message/83662#83666 · In reply to: #83662

Hi Phil,

Am 24.02.2015 um 14:52 schrieb Philip Sturgeon:
> https://wiki.php.net/rfc/anonymous_classes

I like the idea of having anonymous classes, it is very helpful during
development to just try something out without having the burden of
creating a new file and a complete class including namespace and use
declarations, etc.

A great feature of anonymous classes in Java is their ability to access
the private/protected properties of the object they are defined in,
similar to what Closures do in PHP. The thing is, in Java if you access
a variable (without this.), it may be of the current scope, a member of
the current class or a member of the class where the anonymous class was
defined in. In PHP, you have to use $this-> to access class members of
the anonymous class but there is some $outer-> or similar variable
missing for the access. You can as a work around pass all members by
reference via the constructor, but that is really not nice.

In addition, if you define an anonymous class inside a "real" class and
pass another instance of the outer class, the anonymous class can still
access the private/protected methods imho. Any thoughts how to handle
this or should we just ignore it for now?

Second thing is serialization. PHP closures can not be serialized, does
the same apply for anonymous classes? It would be really nice if such
anonymous classes could e.g. send via a command bus or something to be
executed on another host.

Thanks
Dennis

P.s.: there is a footnote in the RFC that does not belong there is think

---

## #83667 — Dmitry Stogov — 2015-02-24T14:34:33+00:00

URL: https://externals.io/message/83662#83667

On Tue, Feb 24, 2015 at 5:19 PM, Philip Sturgeon <pjsturgeon@gmail.com>
wrote:

> 
> > […]
> introduced.
> > […]
>
> 1. You can absolutely assign the instantiated classes to variables.
>
> Check out this test in the patch:
>
> https://github.com/krakjoe/php-src/compare/anon#diff-25e330fb5a98810de178a5b798102d01R1
>
>
In tests you assign instantiated objects.

$a = new class {...};
$b = new class {...};

I'm talking about classes as first class objects.

$c = class {...};
$a = new $c;
$b = new $c;



> 2. Why do you say they cannot be passed to a function? I can add a
> test if you can give me an example of what you're suggesting doesn't
> work.
>
> 3. Not sure why we'd need a Closure-alike object. Anonymous classes
> are just a class, and classes have all the types and hinting
> functionality of regular classes. You don't need to implement a class
> to let people know its a class.
>
> Maybe you could expand on that a bit? :)
>

I tried it in the example above.

Also, classes may be useful without objects at all (just static properties
and methods).

$c = class {...};
$c::static_foo();

Thanks. Dmitry.

---

## #83671 — Philip Sturgeon — 2015-02-24T15:31:41+00:00

URL: https://externals.io/message/83662#83671

> 
> > […]
>
> I don't buy this argument. If your class loader or PSR prevents you from
> temporarily adding a 2nd bogus class to the same file (not talking about
> best practices here, obviously) then there's the culprit and it's
> nothing the language needs to fix.
>
> ~Florian
>
> --
> 
> 
>

Your reply seems to assume that avoiding rules in a PSR is the only
benefit of the RFC, which is weird when there is a whole RFC full of
benefits of this RFC.

Also, how do you "Temporarily" add a 2nd bogus class to the same file?

Also again, why is it bogus?

This RFC allows people to use really simple classes, which implement
various things, or provide simple decoration, or insanely easy
stubbing, or all sorts of other functionality without having to define
it way at the top of the file, or in another file, or whatever. Not
just bogus junk, but actual real uses.

My mention of PSR (and PEAR and Zend which you didn't mention) was
purely a sidenote of "This is how the community is doing things" which
is always relevant to mention, and not a complaint about PSRs. This
was common practice for the preceding decade, and again is not the
crux of this conversation.

---

## #83672 — Philip Sturgeon — 2015-02-24T15:33:23+00:00

URL: https://externals.io/message/83662#83672 · In reply to: #83667

>
>
> On Tue, Feb 24, 2015 at 5:19 PM, Philip Sturgeon <pjsturgeon@gmail.com>
> wrote:
> > […]
>
> In tests you assign instantiated objects.
>
> $a = new class {...};
> $b = new class {...};
>
> I'm talking about classes as first class objects.
>
> $c = class {...};
> $a = new $c;
> $b = new $c;
>
>
> > […]
>
>
> I tried it in the example above.
>
> Also, classes may be useful without objects at all (just static properties
> and methods).
>
> $c = class {...};
> $c::static_foo();
>
> Thanks. Dmitry.

Thank you for the example! Your example explains my question 1, but
doesn't seem to explain 2 or 3.

I'll play around with static usage and show it off in the tests.

---

## #83673 — Florian Anderiasch — 2015-02-24T15:59:13+00:00

URL: https://externals.io/message/83662#83673 · In reply to: #83671

> 
> > […]
> 
> Your reply seems to assume that avoiding rules in a PSR is the only
> benefit of the RFC, which is weird when there is a whole RFC full of
> benefits of this RFC.

My reply was simply re: the quoted paragraph in the mail I directly
replied to, not yours. I simply think "trying something out" is not a
valid use case of anonymous classes.

I can generally like the RFC and still refute arguments in favor of it,
right? :)

~Florian

---

## #83675 — Matthew Leverton — 2015-02-24T16:21:35+00:00

URL: https://externals.io/message/83662#83675 · In reply to: #83662

> Good day!
>
> https://wiki.php.net/rfc/anonymous_classes
>
> There's a little RFC + patch that Joe Watkins put together, and as
> before with the ArrayOf RFC, I'll be helping out.
>
> So, lets get this discussion rolling.
>
Anonymous classes open up slightly new ways to do things. I like to
write a lot of small classes for the purposes of DI and re-usability.
Because of that, the code often looks like:

$foo = new Foo($depend1, $depend2, function() {
  return 'my custom behavior';
});

That's fine when there's only one callback needed, but beyond that it
breaks down. This becomes more readable:

abstract class Foo
{
 ...
}

$foo = new class($depend1, $depend2) extends Foo {
  public function doFoo() {
  }
  public function doBar() {
  }
}

These cases for me are always single-use for the scope of the
application, and often it's inside configuration blocks that are
custom per environment. I have no need to name the class other than
PHP doesn't support anonymous ones.

I'm +1 on the concept, depending on what the maintenance impact that
this would bring to PHP's core. There are enough other ways to
accomplish the same goals that I don't think this is "must have", even
though I'd definitely use it.

Regarding this syntax (from other discussions on the list):

$foo = class { };

I think if such a thing were supported, maybe $foo would just be a
ReflectionClass object. (I haven't really thought that one through...)

--
Matthew Leverton

---

## #83677 — Philip Sturgeon — 2015-02-24T16:44:11+00:00

URL: https://externals.io/message/83662#83677 · In reply to: #83673

> 
> > […]
>
> My reply was simply re: the quoted paragraph in the mail I directly
> replied to, not yours. I simply think "trying something out" is not a
> valid use case of anonymous classes.
>
> I can generally like the RFC and still refute arguments in favor of it,
> right? :)
>
> ~Florian


I gotcha.

Again though, Dennis wasn't saying "trying something out" is the only
benefit, just the one. We can take that argument and shove it under
the rug for sure, but it's perfectly reasonable for me as one of many
arguments for it.

---

## #83678 — Thomas Bley — 2015-02-24T16:53:31+00:00

URL: https://externals.io/message/83662#83678 · In reply to: #83662

here is an example for opening a mysqli connection only when the first query is executed:

$c = new class extends mysqli {
  public function query($query, $resultmode = MYSQLI_STORE_RESULT) {
    if (empty($this->host_info)) parent::real_connect('127.0.0.1', 'user', 'pwd', 'db');
    return parent::query($query, $resultmode);
  }
}

// do sth for some time

$->query('...'); // triggers real_connect
$->query('...'); // connection is already established

I haven't tested this, so I'm only intending to present the idea.

Regards
Thomas


Philip Sturgeon wrote on 24.02.2015 14:52:

> Good day!
> 
> https://wiki.php.net/rfc/anonymous_classes
> 
> There's a little RFC + patch that Joe Watkins put together, and as
> before with the ArrayOf RFC, I'll be helping out.
> 
> So, lets get this discussion rolling.
> 
> It was declined for PHP 5 some time ago, and has returned now to try for PHP 7.
> 
> The usage of anonymous classes to some will be instantly offensive,
> but really it comes down to the use case. The usage of anonymous
> functions compared to declared functions is pretty much the exact same
> thing as anonymous classes.
> 
> Other than examples on the RFC, Fractal would certainly be happy to
> have them: http://fractal.thephpleague.com/transformers/
> 
> Defining a class properly is certainly still going to be the majority
> of uses of classes in PHP. That helps with the Optimizer, and helps
> code reuse.
> 
> Sadly due to the way in which people have had ONE CLASS ONE FILE
> drilled into their head since PEAR and continuing through Zend and
> PSR-0, it can become a PITA to add some simple functionality if a
> small class is needed for one tiny thing.
> 
> Anonymous functions alleviate that annoyance with a simple and
> consistent feature that just give people a nice simple option to get
> their jobs done, without hitting autoloaders and file systems to do
> it.

---

## #83679 — Mike Willbanks — 2015-02-24T17:21:42+00:00

URL: https://externals.io/message/83662#83679 · In reply to: #83662

On Tue, Feb 24, 2015 at 7:52 AM, Philip Sturgeon <pjsturgeon@gmail.com>
wrote:

> Good day!
>
> https://wiki.php.net/rfc/anonymous_classes
>
> There's a little RFC + patch that Joe Watkins put together, and as
> before with the ArrayOf RFC, I'll be helping out.
>
> So, lets get this discussion rolling.
>
> It was declined for PHP 5 some time ago, and has returned now to try for
> PHP 7.
>
> The usage of anonymous classes to some will be instantly offensive,
> but really it comes down to the use case. The usage of anonymous
> functions compared to declared functions is pretty much the exact same
> thing as anonymous classes.
>
> Other than examples on the RFC, Fractal would certainly be happy to
> have them: http://fractal.thephpleague.com/transformers/


I would also find myself to be a very happy consumer of this.  It can
provide the opportunity of getting rid of a large amount of boilerplate.
In addition, there has been several times when implementing single use
extensions for say view libraries (Plates extensions comes to mind) or
Plugin handling for things like Zend Framework 2 and there has been several
times I utilize a closure with an array to get around having an object
simply due to you want to have a callback but with some form of
definition.  I think there is a very large use case here and something that
would be a great addition to the language.  Sure, I could make a class and
extend it just like this would do but for the convenience of the
implementation it is sometimes better to do a simple closure.

Defining a class properly is certainly still going to be the majority
> of uses of classes in PHP. That helps with the Optimizer, and helps
> code reuse.
>
> Sadly due to the way in which people have had ONE CLASS ONE FILE
> drilled into their head since PEAR and continuing through Zend and
> PSR-0, it can become a PITA to add some simple functionality if a
> small class is needed for one tiny thing.
>

I see the point here, but the argument to me seems void.  Nothing wrong
with a simple class one file for a small class.


>
> Anonymous functions alleviate that annoyance with a simple and
> consistent feature that just give people a nice simple option to get
> their jobs done, without hitting autoloaders and file systems to do
> it.

---

## #83680 — Philip Sturgeon — 2015-02-24T18:16:17+00:00

URL: https://externals.io/message/83662#83680 · In reply to: #83679

>
>
> On Tue, Feb 24, 2015 at 7:52 AM, Philip Sturgeon <pjsturgeon@gmail.com>
> wrote:
> > […]
>
>
> I would also find myself to be a very happy consumer of this.  It can
> provide the opportunity of getting rid of a large amount of boilerplate.  In
> addition, there has been several times when implementing single use
> extensions for say view libraries (Plates extensions comes to mind) or
> Plugin handling for things like Zend Framework 2 and there has been several
> times I utilize a closure with an array to get around having an object
> simply due to you want to have a callback but with some form of definition.
> I think there is a very large use case here and something that would be a
> great addition to the language.  Sure, I could make a class and extend it
> just like this would do but for the convenience of the implementation it is
> sometimes better to do a simple closure.
>
> > […]
>
>
> I see the point here, but the argument to me seems void.  Nothing wrong with
> a simple class one file for a small class.
>

Something doesn't have to be "wrong", another approach can just be
more convenient, or handy for different use cases.

One class one file can be rather slow depending on the autoloader
setup, and depending on whether zend optimizer is enabled or not. For
a distributed application running on mostly crap shared hosting,
relying on Zend Optimizer is not an option, so the more of these
little one-class one-file situations you have the worse it becomes.

This RFC offers a solution for people that is not "Jam a bunch of
these classes at the top of the current file" or "Make a whole load of
one-time use classes to avoid that mess, plus people will snort and
shame you for failing to follow decade old best practices."

---

## #83681 — S.A.N — 2015-02-24T18:37:33+00:00

URL: https://externals.io/message/83662#83681 · In reply to: #83680

Would have been more useful, inline sintex like JSON:

$object =
{
    'property': $value,
    'method':  function (){...}
};

$object->property;
$object->method();

---

## #83682 — Philip Sturgeon — 2015-02-24T18:49:36+00:00

URL: https://externals.io/message/83662#83682 · In reply to: #83681

> Would have been more useful, inline sintex like JSON:
>
> $object =
> {
>     'property': $value,
>     'method':  function (){...}
> };
>
> $object->property;
> $object->method();

I know what you're saying here, and object literals like this would be
rather interesting someday. They are, however, quite different to the
concept of anonymous classes.

JSON syntax would make it very hard for the usual PHP functionality to
be used. Properties and methods look the same, visibility scopes
cannot be used, implementing interfaces becomes impossible, traits
dont have a home, etc. By the time you have catered to all of that you
have something very different to JSON, and very different to PHP.

Or, you have the syntax being proposed here, which is identical to
existing declared class syntax other than there being no name.

Another RFC to replace $foo = (object) [ 'foo' => 'bar' ]; someday
would be nice, but that is not what this is up to.

---

## #83683 — S.A.N — 2015-02-24T19:06:20+00:00

URL: https://externals.io/message/83662#83683 · In reply to: #83682

2015-02-24 20:49 GMT+02:00 Philip Sturgeon <pjsturgeon@gmail.com>:
> 
> > […]
>
> I know what you're saying here, and object literals like this would be
> rather interesting someday. They are, however, quite different to the
> concept of anonymous classes.
>
> JSON syntax would make it very hard for the usual PHP functionality to
> be used. Properties and methods look the same, visibility scopes
> cannot be used, implementing interfaces becomes impossible, traits
> dont have a home, etc. By the time you have catered to all of that you
> have something very different to JSON, and very different to PHP.
>
> Or, you have the syntax being proposed here, which is identical to
> existing declared class syntax other than there being no name.
>
> Another RFC to replace $foo = (object) [ 'foo' => 'bar' ]; someday
> would be nice, but that is not what this is up to.

Yes, is problem - properties and methods look the same, how to solve
this problem in PHP I do not know.
Perhaps PHP could interpret this code:
$object =
{
    'property' => $value,
    'method' => function (){...}
};

AS

$object = new class
{
  public $property = $value;
  public function method (){...}
}

Use case - inline object without inheritance and traits, only the
properties and methods it brief and easily understood JSON syntax, I
think it would be popular with developers of PHP.

Thank.

---

## #83684 — Thomas Bley — 2015-02-24T19:07:13+00:00

URL: https://externals.io/message/83662#83684 · In reply to: #83681

I'm not sure if json syntax is better than PHP here:

$object = (object)[
  'property'=>$value,
  'method'=>function(){...}
];
$object->property;
$object->method->__invoke();


S.A.N wrote on 24.02.2015 19:37:

> Would have been more useful, inline sintex like JSON:
> 
> $object =
> {
>    'property': $value,
>    'method':  function (){...}
> };
> 
> $object->property;
> $object->method();

---

## #83686 — Stanislav Malyshev — 2015-02-24T19:22:36+00:00

URL: https://externals.io/message/83662#83686 · In reply to: #83662

Hi!

> https://wiki.php.net/rfc/anonymous_classes
> 
> There's a little RFC + patch that Joe Watkins put together, and as
> before with the ArrayOf RFC, I'll be helping out.
> 
> So, lets get this discussion rolling.

This is a nice and clear proposal, however I'm not sure I'm completely
convinced about the necessity of it. In Java this kind of pattern is
used very frequently, because Java is a statically typed language where
it is the only way to achieve dynamic interface, and has other
capabilities, see below. In PHP, there are other ways (and can be made
more ways, such as more support for duck typing).

Also, the question arises when comparing this to Java - would anonymous
class functions be closures connected to the environment? In Java, they
are and that is what they are most frequently used for - to make
contextualized callbacks. In PHP, you need special syntax to capture the
environment, so how that would work? Also, what about scope access, etc.?

> Sadly due to the way in which people have had ONE CLASS ONE FILE
> drilled into their head since PEAR and continuing through Zend and
> PSR-0, it can become a PITA to add some simple functionality if a
> small class is needed for one tiny thing.

One class/one file may be a good idea in general for a big project, but
as they say, any feature that can not be turned off when needed is a bug.
-- 
Stas Malyshev
smalyshev@gmail.com

---

## #83688 — Stanislav Malyshev — 2015-02-24T19:25:54+00:00

URL: https://externals.io/message/83662#83688 · In reply to: #83666

Hi!

> I like the idea of having anonymous classes, it is very helpful during
> development to just try something out without having the burden of
> creating a new file and a complete class including namespace and use
> declarations, etc.

I think this particular argument is a bit backwards. In PHP, you
certainly don't need to create new file to just introduce a new class.
If you're working within a framework that makes it a problem, time to
think if the framework you're using is fit for your purposes. But PHP
certainly does not impose such limitations.

> A great feature of anonymous classes in Java is their ability to access
> the private/protected properties of the object they are defined in,
> similar to what Closures do in PHP. The thing is, in Java if you access
> a variable (without this.), it may be of the current scope, a member of
> the current class or a member of the class where the anonymous class was
> defined in. In PHP, you have to use $this-> to access class members of

That may be a problem to implement, exactly since you need $this in PHP.

> Second thing is serialization. PHP closures can not be serialized, does
> the same apply for anonymous classes? It would be really nice if such

Serializing is not a problem, unserializing would be - as there may be
no class for this object to instantiate.

-- 
Stas Malyshev
smalyshev@gmail.com

---

## #83810 — Philip Sturgeon — 2015-02-25T17:49:02+00:00

URL: https://externals.io/message/83662#83810 · In reply to: #83688

> Hi!
>
> > […]
>
> I think this particular argument is a bit backwards. In PHP, you
> certainly don't need to create new file to just introduce a new class.
> If you're working within a framework that makes it a problem, time to
> think if the framework you're using is fit for your purposes. But PHP
> certainly does not impose such limitations.
>
> > […]
>
> That may be a problem to implement, exactly since you need $this in PHP.
>
> > […]
>
> Serializing is not a problem, unserializing would be - as there may be
> no class for this object to instantiate.
>
> --
> Stas Malyshev
> smalyshev@gmail.com
>
> --
> 
> 
>

If anyone wants to have a play with anonymous classes, our friends
over at 3v4l.org have made this incredibly easy to do:

http://3v4l.org/elh6I/rfc#rfc-anonymous_classes

Awesome.

---

## #84249 — Robert Stoll — 2015-03-03T17:03:08+00:00

URL: https://externals.io/message/83662#84249 · In reply to: #83662

Hi Philip

> -----Ursprüngliche Nachricht-----
> Von: Philip Sturgeon [mailto:pjsturgeon@gmail.com]
> Gesendet: Dienstag, 24. Februar 2015 14:52
> An: PHP Internals
> Betreff: [PHP-DEV] [RFC] Anonymous Classes
> 
> Good day!
> 
> https://wiki.php.net/rfc/anonymous_classes
> 
> There's a little RFC + patch that Joe Watkins put together, and as before with the ArrayOf RFC, I'll be helping out.
> 

[Robert Stoll] 
I like the RFC +1 :)

Can I also use traits in combination with anonymous classes?=3D20

---

## #84291 — Philip Sturgeon — 2015-03-04T15:48:59+00:00

URL: https://externals.io/message/83662#84291 · In reply to: #84249

> Hi Philip
>
> > […]
>
> [Robert Stoll]
> I like the RFC +1 :)
>
> Can I also use traits in combination with anonymous classes?=3D20
>

You can indeed use traits. Should I add this as an example and shove a
test in there?

---

## #84292 — Robert Stoll — 2015-03-04T16:16:47+00:00

URL: https://externals.io/message/83662#84292 · In reply to: #84291

> -----Ursprüngliche Nachricht-----
> Von: Philip Sturgeon [mailto:pjsturgeon@gmail.com]
> Gesendet: Mittwoch, 4. März 2015 16:49
> An: Robert Stoll
> Cc: PHP Internals
> Betreff: Re: [PHP-DEV] [RFC] Anonymous Classes
> 
> 
> > […]
> 
> You can indeed use traits. Should I add this as an example and shove a test in there?
> 
> --
>  

I would, maybe I oversaw it but I was not sure if it is possible after reading the description of your RFC.

---

## #84386 — Philip Sturgeon — 2015-03-06T19:14:36+00:00

URL: https://externals.io/message/83662#84386 · In reply to: #84292

Right, this here RFC has been drastically improved.

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

Anyone got any doubts or troubles at this point?

It's about 5 days until the vote starts.

---

## #84391 — Stanislav Malyshev — 2015-03-06T23:42:33+00:00

URL: https://externals.io/message/83662#84391 · In reply to: #84386

Hi!

> Right, this here RFC has been drastically improved.
> 
> https://wiki.php.net/rfc/anonymous_classes
> 
> Anyone got any doubts or troubles at this point?
> 
> It's about 5 days until the vote starts.

Couple of points to clarify:

1. Is the new syntax "new class ..." or just "class ..." and new works
the same? I.e. could you do:

$foo = class extends Callback { ... }
$bar = new $foo;

2. What is the scope of the anonymous class? Can it get access to
parent's variable scope? Private functions?

-- 
Stas Malyshev
smalyshev@gmail.com

---

Next page: https://externals.io/message/83662.md?page=2
