nikic / scalar_objects

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

Clarification on the limitation in PHP 5.6 #17

Closed terah closed 9 years ago

terah commented 10 years ago

Hi Nikic,

I love this extension. On your readme you state "Due to technical limitations, it is no longer possible to create mutable APIs for primitive types in PHP 5.6 or higher. Modifying $this within the methods is not possible (or rather, will have no effect, as you'd just be changing a copy)."

Can you confirm that this extension will not work at all on PHP > 5.5?

Thanks!

nikic commented 10 years ago

The extension should work on PHP 5.6, you just won't be able to implement methods like $array->push() which will modify the $array. It actually turned out that this doesn't work properly on PHP 5.5 either if you use $obj->array->push(). So basically APIs implemented using this should all be immutable.

The extension doesn't yet work with PHP 7 and will also need to use a slightly different approach there. In particular it won't be able to use $this and should pass an extra argument instead (which also solves some other issues). I haven't gotten around to writing a version for that yet.

terah commented 10 years ago

Thanks for the clarification. What are the chances that this functionality will make it into the core? I've been looking around for discussion/rfc on this topic and couldn't find too much specific to scalar objects. For me, this really could solve the consistent function arguments/scalar type hinting/method chaining request that keep coming up. Do you have any links to serious discussion regarding the possible inclusion of this into the core?