nikic / scalar_objects

Extension that adds support for method calls on primitive types in PHP
MIT License
1.13k stars 44 forks source link

Can you bring this to PHP RFC? #20

Open HallofFamer opened 9 years ago

HallofFamer commented 9 years ago

I took a look at it and I very like what is being implemented. In my own framework I use classes for Int, Float, String and Array, but sometimes it can be a bit tedious(like having to write new String("abc") than just "abc"). This library will fix a lot of issues in my codebase, and make coding 10x more enjoyable. Also if its implemented at the PHP core, there's a chance to suggest a way to make even more elegant syntax work, such as "abc"->toUpper() which does not happen yet. So, will you consider moving this to RFC and possibly have PHP internals implement it in PHP 7?

terah commented 9 years ago

I think there are a lot of PHP devs that would love to see this in the core...

HallofFamer commented 9 years ago

yeah of course, for developers who want to use strongly typed PHP scalars, this will help tremendously. Please do consider bringing it to PHP RFC.

nikic commented 9 years ago

I won't have the time to propose this for inclusion in PHP 7. Adding this to core would require quite a lot of work and feature freeze is not far away.

By the way, I already added support for syntax like "abc"->toUpper() and [1, 2, 3]->reverse() to PHP 7 (it will just throw a runtime error). So once this extension is ported to PHP 7, you'll be able to use that syntax in conjunction with the ext.

HallofFamer commented 9 years ago

I see, thats a pity, I really hope to see this on PHP 7.0, but guess it wont be there at least till 7.1... Still, you can start an RFC to prepare for the future, even if it will not be going to voting phase anytime soon, right?

And its very good news, I very love the syntax like "mystring"->length() and [2, 5, 4, 6]->sort(). It will be very useful, cant wait for the new Scalar object for PHP 7!

TRPB commented 9 years ago

Shame, I'd have also loved to have seen this in PHP7. As I mentioned in one of the other issues, this is a perfect opportunity to fix the inconsistent function naming and parameter orders... $str->replace(), $array->combine() etc.

alanwillms commented 9 years ago

@nikic what about modifying $self within the handlers? It will be possible in PHP 7?

nikic commented 9 years ago

@alanwillms Nope, the current VM implementation doesn't allow this. With enough effort it might be possible, but would probably have negative performance impact for all other method calls (which is pretty much a no-go).

alanwillms commented 9 years ago

@nikic not modifying $self may be a good thing since it enforces immutability.

Now that PHP 7.0 is frozen and won't have any new features, will you open a RFC targeting 7.1?

c9s commented 9 years ago

+1, this looks really great and I am looking forward to see this in PHP 7!

Strate commented 9 years ago

:+1: for this in php core

TheXardas commented 9 years ago

Yep, +1.

alexkvak commented 9 years ago

+1

sirsnyder commented 9 years ago

+1

kandy commented 9 years ago

Also will be good to split to two RFC. One about engine level ability. And one about user space registration.

dominikzogg commented 9 years ago

+1

robob4him commented 9 years ago

@nikic "once this extension is ported to PHP 7"

Any progress on this?

vbsessa commented 9 years ago

+1

brzuchal commented 8 years ago

:+1:

dgafka commented 8 years ago

+1

ghost commented 8 years ago

+1

jkonefal commented 8 years ago

:+1:

event15 commented 8 years ago

+1

KennetPL commented 8 years ago

+1

danizord commented 8 years ago

:+1:

lgabeskiria commented 8 years ago

+1

ctrl-f5 commented 8 years ago

+1

marcelgsantos commented 8 years ago

:+1:

brzuchal commented 8 years ago

@nikic are there any chances to bring this to RFC into the core of PHP? This feature is awesome and there are plenty of people looking forward for this.

devypt commented 8 years ago

+1

nilportugues commented 8 years ago

+1

ciscoo commented 8 years ago

Just a reminder everyone that you can add a reaction to comments rather than cluttering the comments with +1.

whatsupdan commented 8 years ago

+1

SerafimArts commented 8 years ago

+1

eduardor2k commented 8 years ago

+1

exts commented 8 years ago

+1

ctrl-f5 commented 8 years ago

please stop replying "+1", to vote just add reaction to the original comment. You are spamming all participants' mailboxes.

jens1o commented 7 years ago

Will this be possible in PHP 7.2?

ctrl-f5 commented 7 years ago

no, there hasn't even been an RFC for this, so it can not possibly be scheduled to be in a future release.

jclyons52 commented 7 years ago

What can we do to bring this closer to an RFC?

Rastusik commented 6 years ago

+1

mustafatoker commented 6 years ago

+1

mpyw commented 6 years ago

Hope for PHP 8.x or 9.x

qwerty199369 commented 6 years ago

This feature is awesome! 👍 Please do consider bringing it to PHP RFC. @laruence @nikic 👍

alanwillms commented 6 years ago

PHP core developers are discussing about tagging the next release after 7.3 as 8.0. Maybe now is the time.

q2dg commented 5 years ago

An entire year has passed already...do you know any news on this? Thanks!

mpyw commented 5 years ago

So interesting but handlers should be applied in a specific scope.

HRADigital commented 5 years ago

An entire year has passed already...do you know any news on this? Thanks!

It doesn't seam to be planned for v8!

mpyw commented 5 years ago

C# Extension Method

Definitively I think C#'s Extension Method is our goal.

Atulin commented 5 years ago

So it hasn't gone to an RFC for... four years now? What's stopping it?

HallofFamer commented 5 years ago

@mpyw yup this one has the potential to allow any types to be extended instead of just primitive types, though unlike C# which is compiled, in PHP you will have to manually include the files that contain extension methods.

Anyway, I think, its about time to bring this to PHP RFC. It will be a neat feature for PHP 8, a good chance to introduce OO API for scalar types, as well as fixing the messy function names that cannot be touched due to backward compatibility issue.