Skip to content

Add undocumented FFI\CType methods #1227

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

Merged
merged 2 commits into from
Jan 5, 2022
Merged

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Dec 21, 2021

Currently, the FFI\CType class page warns due to the missing documentation of its methods.

Pages are generated by docgen.php

@cmb69
Copy link
Member

cmb69 commented Dec 21, 2021

Oh, indeed, documenting php/php-src#7217 has apparently been forgotten so far. I think we should note that in the migration guide as well, and maybe someone who has already been working with these new APIs might want to fill in some of documentation gaps right away. I'm going to add a help-wanted label, and suggest to wait a while; otherwise committing as is should be okay.

@cmb69 cmb69 added the help wanted Extra attention is needed label Dec 21, 2021
mumumu referenced this pull request Dec 22, 2021
XPointer evaluation failed: #xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.ffi-ctype')/db:refentry/db:refsect1[@ROLE='description']/descendant::db:methodsynopsis[not(@ROLE='procedural')])

According to stub file, method entries will be added.

https://github.com/php/php-src/blob/97cdf62a6a1d8491f8d1ef1580f344400eb51f1d/ext/ffi/ffi.stub.php#L77-L100
@mumumu
Copy link
Member

mumumu commented Dec 22, 2021

This PR will fix the following build warning.

45aaa3f

Copy link

@fizietechD fizietechD left a comment

Choose a reason for hiding this comment

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

@ #

@cmb69
Copy link
Member

cmb69 commented Jan 2, 2022

I just noticed that the FFI\CType reflection API also introduced a bunch of class constants. Apparently, we don't have class constants anywhere in the stub files; is that deliberate? If there is no particular reason to not have them there, I suggest to add them for documentation purposes; although, of course, someone would have to implement that. And also, the transition for the docs might be quite some work, since (most?) exisiting documentation puts the class constants in the predefined constants sections, e.g. https://www.php.net/manual/en/zip.constants.php.

@kocsismate
Copy link
Member Author

Apparently, we don't have class constants anywhere in the stub files; is that deliberate?

Yes, unfortunately, this is due to a technical limitation: we can't autogenerate constants which have a C constant value. However, I made a POC in order to add simple constant autogeneration support in stubs: php/php-src#7434

As Nikita wasn't really impressed, I put this PR on hold. However, I think extensions could benefit from this feature, and I agree that it would be advantageous for class synopsis generation as well.

And also, the transition for the docs might be quite some work, since (most?) exisiting documentation puts the class constants in the predefined constants sections

Oh, I wasn't aware of this. Thanks for bringing this to my attention!

@cmb69
Copy link
Member

cmb69 commented Jan 2, 2022

Thanks for pointing out that PR! Actually, I'm not in favor of documenting all constants with their value; while it may make sense for some (e.g. error constants, where one wants to quickly look up what the result of json_last_error() means), it easily may defeat the purpose of abstracting over certain hard-coded values. Still, having the defined constants documented without their values is valuable (and it won't take long for a user note to appear which lists the constants with their values).

And note that I'm actually in favor of moving class constants from the predefined constants sections to the classs synopses, although I'm not sure whether this is currently supported by PhD.

@kocsismate
Copy link
Member Author

Still, having the defined constants documented without their values is valuable (and it won't take long for a user note to appear which lists the constants with their values).

I would be more happy if constants in stubs could be used/validated by php-src itself in any way. Otherwise we'll likely end up with outdated information in a while. That's why my PR only adds "simple" constant (~ constants whose value is a literal rather than a C constant) support so that we don't have to refer to C constants in the stubs, but we can still benefit from a more complete class entry and class synopsis page autogeneration. E.g. JSON error codes (php_json_error_code) would be supported, while the LIBXSLT_VERSION wouldn't.

And note that I'm actually in favor of moving class constants from the predefined constants sections to the class synopses, although I'm not sure whether this is currently supported by PhD.

fieldsynopsis elements can be used to display class constants. For instance: https://www.php.net/manual/en/class.datetimeinterface.php But the migration from the predefined constants sections to the class synopses for sure would be a PITA.

@cmb69
Copy link
Member

cmb69 commented Jan 3, 2022

I would be more happy if constants in stubs could be used/validated by php-src itself in any way. Otherwise we'll likely end up with outdated information in a while. That's why my PR only adds "simple" constant (~ constants whose value is a literal rather than a C constant) support so that we don't have to refer to C constants in the stubs, but we can still benefit from a more complete class entry and class synopsis page autogeneration. E.g. JSON error codes (php_json_error_code) would be supported, while the LIBXSLT_VERSION wouldn't.

One does not necessarily exclude the other. In the stubs, constants that refer to C constants could have an UNKNOWN value, and for the docs we could still decide whether we want to display the values or not.

fieldsynopsis elements can be used to display class constants.

Ah, right. Thanks!

But the migration from the predefined constants sections to the class synopses for sure would be a PITA.

Well, in my opinion, that should be done anyway. The only drawback generating this from a stub file would be that grouping would not be supported (at least not out of the box).

@kocsismate
Copy link
Member Author

One does not necessarily exclude the other. In the stubs, constants that refer to C constants could have an UNKNOWN value, and for the docs we could still decide whether we want to display the values or not.

I like this idea! :) Believe it or not, there are only a handful of class synopses left which still needs synchronization :) And the rest of the diff is due to the missing constants. So adding support for constants would improve the situation of class synopsis generation much more.

Well, in my opinion, that should be done anyway. The only drawback generating this from a stub file would be that grouping would not be supported (at least not out of the box).

Yeah, I think we could add support for grouping by using @constant-group in the stubs :)

@kocsismate
Copy link
Member Author

How much should we wait with the merge? Can we go ahead now? I doubt there will be any volunteers to help with this PR :S

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Ah, right! Please go ahead.

@cmb69 cmb69 removed the help wanted Extra attention is needed label Jan 5, 2022
@kocsismate kocsismate merged commit 8161936 into php:master Jan 5, 2022
tiffany-taylor pushed a commit to tiffany-taylor/doc-en that referenced this pull request Jan 16, 2023
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.

4 participants