-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support interfaces #35
Comments
Yeah, interfaces are not supported yet. I will probably add support as soon as I have a use case for them. If you want to contribute, I am open to reviewing and aiding in the implementation of this feature. |
Hmm. So what if we add methods to generated classes that represent Object types and let them implement interfaces representing Interface types for shared fields? |
The generated result objects allow access to fields in the form of properties. I think this is more elegant than methods because:
That said, interfaces without methods still provide value:
|
I see the PR, just few notes on those interfaces.
methods would read properties so the same applies, no?
method calls do so? or I don't understand Implemented interfaces only with properties seem a bit dirty as it is not how the language was designed |
Given this code: class Foo {
public ?Foo $bar;
function bar(): ?Foo { return null; }
}
$foo = new Foo; The following will work without error: $foo->bar->bar ?? null; This will throw with $foo->bar()->bar() ?? null; PHP 8 would allow to do it safely and succintly, but even then properties are more terse: $foo->bar()?->bar(); |
Ah ok I see what you meant by that. I go with PHP 8 everywhere. |
I'm trying to generate classes for InterfaceType and it seems not to be supported in ClassGenerator. Is it intentional?
selection is like
but I'm crashing on
sailor/src/Codegen/ClassGenerator.php
Line 251 in 77ba145
Thanks
The text was updated successfully, but these errors were encountered: