-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anon class objects #470
anon class objects #470
Conversation
👍 |
Last commit makes the following possible: class My {
public function Test() {
return new class{};
}
} |
👍 Some questions:
Also note that the |
This supports the use of abstracts/interfaces/traits etc ...
is fine ... Anonymous classes are normal classes without (programmer declared) names, so ReflectionClass/var_dump/instanceof will work as you expect Don't see a reason for it to interfere with #438 ... |
make sure use of class_token is correct revert changes to znode typedef, reuse op.ptr
Not sure that I like this proposal, because syntax is too bad, especially with defining new classes and interfaces inside functions. May be we choose a Java way of private|protected classes or interfaces inside the concrete class except anonymous classes? So classes and interfaces can be defined inside the body of class but will not be available for general use outside. |
Any clue about how object serialization will work with this? |
Can you provide any examples where one can not handle the situation without anon class ? Don't you think this will break some of the SOLID paradigms ? |
How is this different from $var = new stdClass; ? |
Hi chaps, please see the RFC and @Internals for updates and answers ... |
@yagmikita Normally way I will expect serialize/unserialize working with any object that is not dependent of a resource. In this case, I will not able to unserialize an anon class, because there is not class name. Let me know if I could not explain well. |
I see, looks really nice, but whats the colon : used in front of the visibility modifier? Its just for testing purpose, right? o_o |
Yeah, correct, it's gone now, we're over it ... I'll be updating the rfc tomorrow with the new version information, couple of things left to do on it, though you should be able to build and pass tests ... |
Wow this is in voting phase now, excellent, cant wait to see how it ends up with. |
Why is the poll looking so horrible now? I dont remember there was much criticism about anonymous class before it went into voting phase, do people seriously reject a feature just because they either dont understand how it works or that they dont find it useful 'cause they are never gonna use it? How did goto get past the voting phase? |
We have a vote because it's difficult to extrapolate an opinion or consensus from mailing lists ... there's not much can be done, the community has spoken ... apparently ... |
I see, guess you dont really know why they are opposing it? The only possible reason I think of is that they dont understand useful it is. I dont use generators or finally, but if I have a chance Id still vote yes for them both since I can see how they help certain developers to achieve their goals. The fact that you dont find something beneficial or that it does not make sense to you does not dictate that the other people feel the same way, Unfortunately, some people refuse to understand that... sigh And if I may ask, would you turn this into a PECL extension if it gets rejected and continue to develop the inner class? Will you continue to work on it at times so that it will be compatible with PHP 5.6, 5.7 and onwards? |
How strange. I wouldn't have imagined that there could be a problem with a feature which encourages people to use objects more. |
@HallofFamer not possible to do language changes in an extension, you must be able to patch parser ... so no ... pretty much end of the road ... maybe it can be brought up again later on but there's not, realistically, much point ... |
Why do people vote against this thing but vote for https://wiki.php.net/rfc/variadics ... wtf |
I see, thats too bad. I do hope you consider at least make it compatible with each major PHP releases beyond the next version(PHP 5.6, 5.7 etc). There are other features like operator overloading, which is available on PECL and got updated when PHP 5.3, 5.4 and then 5.5 was released. @adrienbrault: But seriously, variadics is a useful feature, like 'finally'. But just like 'finally', its a minor feature and PHP 5.6 is going to be a joke if variadics is labeled as its greatest new feature implemented. In PHP 5.3 we get namespace, and then PHP 5.4 with trait and PHP 5.5 with generator. Anonymous Class/Inner Class can make PHP 5.6 on par with PHP 5.3 with namespace, unfortunately we get so many stupid people saying no. sigh |
@HallofFamer operator is different, it doesn't require a syntax change (thought I believe the first versions did come with a patch for some features), you can implement operators from an extension just fine ... by the way it was updated because someone happened to come along and ask why it didn't work or compile anymore, despite the fact that operator overloading is clearly useful and can be implemented as part of Zend or self contained in an extension using the APIs that Zend exposes; there is no prolonged effort from within the community to maintain the functionality of that, or nearly any other extension on pecl ... This cannot be reasonably maintained outside of php, nor can inner classes, they both require patches to the parser, there is no reasonable, compatible way to self contain this functionality in an extension, if there were I probably would have saved myself the headache and just done that in the first place ... @adrienbrault you should not try to work out why people act the way they do, there's no evidence at all that our behaviour is logical, or driven by logical concerns, and the only means you have to work it out with is logic, so it cannot be done ... |
I could cry that this is not accepted :-/ |
It cant be helped, PHP internals choose to be stupid and stubborn, now they are rejecting extended keyword support too. sigh Perhaps all they wish for the next version of PHP is a purely procedural amateurish script language like PHP 3.0 lol. |
I can't believe this didn't pass the vote. I thought we were supposed to be moving towards a better OO model inside PHP? |
Instead focussing on minor concerns like UTF support. sigh |
Well UTF support is important, its nice they work on it. This should not rule out anonymous/inner class though in any way. According to what has been revealed so far, the PHP internals do not believe it is useful in this language. I can definitely find some usage myself, but apparently it aint enough to convince them. Also some people speculate that that fact that anonymous class support is too java-like may be one important reason why it was rejected, since everything must fit in PHP's nature. I dont understand though, does PHP have a nature lol? And does it need one? Anyway I just hope this project is maintained at least like some PECL packages that get updated every now and then. When PHP 5.6 officially comes out, I am not sure there will even be a feasible way to install this without breaking the other core functionality. sigh |
PHP's nature is to be blind to OO design patterns. Personally I think we should be moving towards a Non-BC break PHP with nicer OO and the ability to choose to use types if you need them. Multipurpose, and helpful. Instead of backward and confused. Still. There has been some progress. |
umm I wonder though, if I have a custom build PHP and I want to add anonymous class support, do I only have to look for the file changes in this pull request and make these changes myself in the source C code? Or are there something else that needs to be modified, especially to make this work with later PHP versions? |
Yes, but this patch are againt a certain PHP version, it might have difference. |
if you need help, you can contact me too :) |
@reeze : Thank you so much, I very appreciate this. |
@reeze: FAILED TEST SUMMARYdeclare bare anonymous class [tests/anon/001.phpt] And of course, using anonymous class in an actual php file on apache server will fail, throwing T_CLASS kind of error. Did I do anything wrong? The changes seems to be perfectly compatible with PHP 5.5 or 5.6, but it does not seem to work for me... Do you have any ideas how I can get this to work? Thanks. |
Hi I am on holiday not,I will check it out maybe several days later:) On 17 February 2015 at 14:43, HallofFamer [email protected] wrote:
Reeze Xia |
@reeze : No problem, thank you. Maybe I can get it to work before you come back, I hope for the best. And enjoy your vacation! |
@HalloFamer anything I could do? :) |
@reeze: Sure, I'd like to see what was wrong with the modifications I made to a customized PHP 5.6.5 with anonymous class. It seems that all tests for anonymous class have failed, and I suspect the issue is more complicated. At this moment, would you mind trying to compile it on your machine and run the tests to see if it fails the tests too? And if so, I will think about what we can do next. I've uploaded the PHP 5.6.5 with anonymous class support below, thanks. |
allow anonymous class objects
Thoughts ??