Skip to content

Allow for arbitrary (class) attributes in stubs #8839

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

Closed
wants to merge 5 commits into from

Conversation

bwoebi
Copy link
Member

@bwoebi bwoebi commented Jun 21, 2022

Building on top of #8776, for flexibility and usage in other extensions, i.e. avoiding hardcoding attribute declarations.

This can be easily extended to other types of attributes (params, etc.).

@TimWolla
Copy link
Member

Would it be possible to add the Attribute attribute to the internal attributes with this?

zend_attribute *attr = zend_add_class_attribute(ce, zend_ce_attribute->name, 1);
ZVAL_LONG(&attr->args[0].value, flags);
zend_string_release(lcname);

As that one also has a parameter, it would serve as a good test case for the all the logic.

@bwoebi
Copy link
Member Author

bwoebi commented Jun 21, 2022

Good point, let me do this :-)

@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch from abb5725 to a5742a8 Compare June 22, 2022 10:01
@bwoebi
Copy link
Member Author

bwoebi commented Jun 22, 2022

@TimWolla done

@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch from a5742a8 to 40cca26 Compare June 22, 2022 10:03
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, this LGTM as far as I'm qualified to tell. Thanks!

@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch 3 times, most recently from fa98cbf to 74167fe Compare June 22, 2022 14:38
@bwoebi
Copy link
Member Author

bwoebi commented Jun 30, 2022

@kocsismate Is this good to merge?

@kocsismate
Copy link
Member

@bwoebi probably yes, but I'm on vacasion now, and can have a look until Monday.

bwoebi added 4 commits July 4, 2022 18:10
This can be easily extended to other types of attributes.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
…nce constants

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch from 498a602 to 2231393 Compare July 4, 2022 16:10
@bwoebi
Copy link
Member Author

bwoebi commented Jul 4, 2022

@kocsismate Looks good now? :-)

@@ -131,6 +157,8 @@ class Context {
public $forceRegeneration = false;
/** @var iterable<ConstInfo> */
public iterable $allConstInfos = [];
/** @var FileInfo[] */
public array $parsedFiles = [];
Copy link
Member

@kocsismate kocsismate Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property type above ($allConstInfos) is a bug in gen_stub.php which is about to be fixed in a soon to be created PR of mine. The issue with it is that the gen_stub.php is part of the build system which is compatible with PHP 7.1 as of now.


foreach ($fileInfo->dependencies as $dependency) {
// TODO add header search path for extensions?
$prefixes = [dirname($stubFile) . "/", ""];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how does it work? The Zend/zend_attributes.stub.php is two directories deeper than ext/zend_test/test.stub.php. Wouldn't is be possible to support relative paths only, like require "../../Zend/zend_attributes.stub.php";?

Copy link
Member Author

@bwoebi bwoebi Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining something like include_path=.;/path/to/source/root/. At least once we add php stubs to headers, we definitely need to include such a "magic" location, whereby the source can be addressed.

I.e. in an external ext, you don't have any proper relative path to use. And the design goal here was that you can still do an in-tree build of exts without any changes. If we were to remove this in php-src, everytime you want to do in-tree development of an ext. you'd have to prepend ../../ to any include, which is not great.

@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch from 1b7db0a to 7b707fa Compare July 5, 2022 14:13
@bwoebi
Copy link
Member Author

bwoebi commented Jul 5, 2022

@kocsismate Guess all open issues are resolved now, right?

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
@bwoebi bwoebi force-pushed the arbitrary-gen-stub-attributes branch from 7b707fa to f490f8e Compare July 5, 2022 14:16
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM as far as I am qualified to tell.


foreach ($fileInfo->dependencies as $dependency) {
// TODO add header search path for extensions?
$prefixes = [dirname($stubFile) . "/", dirname(__DIR__) . "/"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more clear now. I barely realized that previously cwd was used for inclusion so the require wouldn't have worked if you had run gen_stub.php from a subdirectory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I realized that too, thus changed :-D

@kocsismate
Copy link
Member

Very nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants