Hi Phil. I really like this feature and am keen to see it go in. Developers often create classes (which are typically new files) just to extend and implement a small method. This feature could see codebases become much lighter. So a massive thanks for your and Joe’s efforts on this.
I have two quite small points I want to make. Firstly, When a error occurs on an anonymous class the class description isn’t very useful (see http://3v4l.org/9Nbea/rfc#tabs). Instead of “class@0x7f9e33870fd0” Is it possible it could be prefixed with “anonymous” or something a bit clearer. Further to this if the anonymous class extends anything it omits the parent class name in the error message (see http://3v4l.org/UFEbo/rfc#tabs). Is this expected? Could it be something more helpful? Secondly, I think we need to either allow the behaviour or generate an error (similar to anonymous closures) when an anonymous class is serialized. Please observe the following behaviour.. $foo = new class { public function Bar () { echo 'bar'; } }; // This succeeds. I'd argue an error should be generated at this point echo $serFoo = serialize($foo); // Unserialize fails and a notice is generated $unFoo = unserialize($serFoo); // Error generated on call $unFoo->Bar(); see http://3v4l.org/AJY6d/rfc#tabs That’s all. Again, thanks for your efforts. /@leedavis81 On Tue, Feb 24, 2015 at 1:52 PM, Philip Sturgeon <pjsturg...@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. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >