Skip to content
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

Open
wapmorgan opened this issue Sep 7, 2014 · 43 comments
Open

Add support for traits. #504

wapmorgan opened this issue Sep 7, 2014 · 43 comments
Labels
nfr New Feature Request

Comments

@wapmorgan
Copy link

wapmorgan commented Sep 7, 2014

Hey. Hey.
Traits aren't supported yet?

@ovr
Copy link
Contributor

ovr commented Sep 7, 2014

Yeap. It's not supported now

@ovr ovr added the nfr New Feature Request label Sep 7, 2014
@phalcon
Copy link

phalcon commented Sep 7, 2014

5.3 does not support Traits, so this will not probably implemented soon

@ovr
Copy link
Contributor

ovr commented Sep 7, 2014

@phalcon
Notify about use newer version? 5.3 is not supported at the global community EQL
http://php.net/archive/2014.php#id2014-08-14-1

@phalcon
Copy link

phalcon commented Sep 7, 2014

I know, it does not mean no one it's using it

@nkt
Copy link
Contributor

nkt commented Sep 7, 2014

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.

@phalcon
Copy link

phalcon commented Sep 7, 2014

It's a different class type, only available in PHP >= 5.4

http://lxr.php.net/xref/PHP_5_5/Zend/zend_compile.h#161

@nkt
Copy link
Contributor

nkt commented Sep 7, 2014

@phalcon so we could merge trait's methods into every class that uses it for 5.3.

@phalcon
Copy link

phalcon commented Sep 7, 2014

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.

@nkt nkt changed the title It's about a Trait. Add support for traits. Dec 8, 2014
@serebro
Copy link

serebro commented Dec 12, 2014

+1

1 similar comment
@prisis
Copy link

prisis commented Dec 12, 2014

👍

@fezfez
Copy link
Contributor

fezfez commented Dec 12, 2014

👎 There is more important part to implement, like references.
I think it would be more interessting to stabilize the language before adding this type of feature.

@kbtz
Copy link

kbtz commented Dec 12, 2014

@fezfez agreed
-1 for now

@gsouf
Copy link
Contributor

gsouf commented Jan 19, 2015

Trait is an usefull and powerfull feature, though it's only compatible with 5.4 and latter, it mays be used.
Trait are very new in php and people dont use it a lot, mainly cause of 5.3 not being compatible, but i mays change over the years

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

@jimthunderbird
Copy link

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.

@gsouf
Copy link
Contributor

gsouf commented Jan 31, 2015

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.

@hylent
Copy link
Contributor

hylent commented Feb 2, 2015

How about giving up PHP5.3 support?

@gsouf
Copy link
Contributor

gsouf commented Feb 2, 2015

Trait are definitively not supported in php 5.3, right ?

@hylent
Copy link
Contributor

hylent commented Feb 3, 2015

I mean Zephir giving up support for PHP 5.3.
There are problems when running Zephir extensions on PHP 5.3, which I can hardly trace.
By giving up support for PHP 5.3, Traits are reasonable features for Zephir.

@jimthunderbird
Copy link

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

@gsouf
Copy link
Contributor

gsouf commented Feb 3, 2015

Traits are not aimed to be merged into class.
If you want zephir to support this feature , just create another type specific to zephir, and call it mixin for instance.

A php class that uses a trait is NOT compatible with php 5.3 and so should go for zephir.
You should see traits as a part of the public API, not as something used internaly in the library.

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.

@Nirlah
Copy link

Nirlah commented Feb 3, 2015

+1

@sergeyklay
Copy link
Contributor

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? :)

@jimthunderbird
Copy link

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.
https://github.com/jimthunderbird/php-to-c-extension

@aurimasniekis
Copy link

Any update on this?

@flip111
Copy link

flip111 commented Dec 8, 2015

+1

@Green-Cat
Copy link
Contributor

Should be possible now that support for php 5.3 is dropped.

@baohanddd
Copy link

Hope implement traits soon +1

@sergeyklay
Copy link
Contributor

@Green-Cat +1

@aschwin
Copy link

aschwin commented Feb 11, 2016

I figure there are three ways to use traits within Zephir:

  1. As Zephir traits to add functionality for Zephir classes
  2. As PHP traits to add functionality for PHP classes
  3. As a combination of both

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.

@flip111
Copy link

flip111 commented Feb 11, 2016

@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.

@gsouf
Copy link
Contributor

gsouf commented Feb 11, 2016

@flip111 is problably one of the few to understand what a is a trait: a trait is a trait.

@Izopi4a
Copy link
Contributor

Izopi4a commented Mar 11, 2016

+1

3 similar comments
@gtux
Copy link

gtux commented Aug 8, 2016

+1

@kuzmichus
Copy link

+1

@Jurigag
Copy link
Contributor

Jurigag commented Oct 14, 2016

+1

@Jurigag
Copy link
Contributor

Jurigag commented Oct 14, 2016

I will try to add trait support for PHP only, support for zephir itself will be too hard for me i guess.

@Jurigag
Copy link
Contributor

Jurigag commented Oct 15, 2016

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

@ZanderBrown
Copy link

2018 Calling

@wapmorgan
Copy link
Author

More likely we will see php 8 rather than traits

@marcus-sa
Copy link

I feel like this language lacks... everything

@Jurigag
Copy link
Contributor

Jurigag commented Apr 12, 2018

Because it was mainly done for writing phalcon and its features were driven by phalcon development.

@dschissler

This comment was marked as abuse.

@Ilhampasya
Copy link

i hope phalcon need trait, so we can use trait on zephir haha

@Jeckerson Jeckerson added this to the Backlog milestone Apr 12, 2021
@Jeckerson Jeckerson modified the milestones: Backlog, 0.16.0 Oct 24, 2021
@Jeckerson Jeckerson removed this from the 0.16.0 milestone Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nfr New Feature Request
Projects
None yet
Development

No branches or pull requests