-
-
Notifications
You must be signed in to change notification settings - Fork 468
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
Add support for traits. #504
Comments
Yeap. It's not supported now |
5.3 does not support Traits, so this will not probably implemented soon |
@phalcon |
I know, it does not mean no one it's using it |
Does Zend Core support traits? As I know (from opcodes), traits just merges methods into class definition. So we can do the same thing at least in php5.3. |
It's a different class type, only available in PHP >= 5.4 |
@phalcon so we could merge trait's methods into every class that uses it for 5.3. |
Yeah, implementing traits would be easy as you describe, I mean exposing traits as part of the extension will not be possible. They will look as standard classes. |
+1 |
1 similar comment
👍 |
👎 There is more important part to implement, like references. |
@fezfez agreed |
Trait is an usefull and powerfull feature, though it's only compatible with 5.4 and latter, it mays be used. And we cant just merge trait method in the class that use it at the compilation because we wont be able to use the trait from the php code. I'm up to implement it because it's now in the core of php |
I tend to agree with what fezfez said. We might want to stabilize zephir before adding new features. With php parser and abstract syntax tree, we will always be able to merge the code in trait into individual classes. |
By only merging traits into classes, you wlil break the API. Traits are not used only inside the library, they are also usable outside a library. Better no implement them rather than merge methods. |
How about giving up PHP5.3 support? |
Trait are definitively not supported in php 5.3, right ? |
I mean Zephir giving up support for PHP 5.3. |
In my tool PHP-To-C-Ext, it now allows using trait to build zephir based php extensions. Under the hood it just merge all functions in the trait into individual classes. https://github.com/jimthunderbird/php-to-c-extension#example-07 |
Traits are not aimed to be merged into class. A php class that uses a trait is NOT compatible with php 5.3 and so should go for zephir. Sometimes traits are even not used internaly in the library, they are just utilities available for everyone that use the library. Believe me or not, but merging traits into classes and throwing them away from the final extension will bring a lot of confusions. |
+1 |
Judging by this infographic http://php.net/supported-versions.php Soon we will lose the support of 5.4. Maybe it's time to use Traits? :) |
It would be nice if zephir support trait as a built-in structure, if not, right now I am still going the method merging ways, developers have options not to use trait. |
Any update on this? |
+1 |
Should be possible now that support for php 5.3 is dropped. |
Hope implement traits soon +1 |
@Green-Cat +1 |
I figure there are three ways to use traits within Zephir:
I think no.3 is powerful, but confusing. I think no.1 is nice, but I think most useful would be no.2? Best would be both no.1 and no.2, where 1 trait is not both for Zephir and PHP. Like suggested it would be good to make them distinct: mixin for Zephir (no.1), trait for PHP (no.2). No.3 would be implicit be no.1 and no.2. That is confusing. I think if functionality is shared, a no.2 that implements no.1 for example would be better maintainable. |
@aschwin zephir is like a layer on top of C with zend Api. Imo it would be best to make it as transparent as possible so that a class in zephir is a class in php and a trait in zephir a trait in php. If you want to hide stuff from php it would be best to use a technique like optimizers. This technique could probably be extended with more funtionality (on the part of the zephir programmer), but implementing this can be much harder. For example if you want to hide a zephir class from php, because all the classes are registered with the zend api, it would require custom logic so that they can not be used in php. |
@flip111 is problably one of the few to understand what a is a trait: a trait is a trait. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
I will try to add trait support for PHP only, support for zephir itself will be too hard for me i guess. |
But the problem with traits is that internal traits started working just from latest php 7.0.12 for php 7, didn't check php 5 yet. So currently if traits would be added then in php 7 when using in zephir they would work for 7.0.0, but using them in php is working from 7.0.12 |
2018 Calling |
More likely we will see php 8 rather than traits |
I feel like this language lacks... everything |
Because it was mainly done for writing phalcon and its features were driven by phalcon development. |
This comment was marked as abuse.
This comment was marked as abuse.
i hope phalcon need trait, so we can use trait on zephir haha |
Hey. Hey.
Traits aren't supported yet?
The text was updated successfully, but these errors were encountered: