Skip to content

Conversation

TimWolla
Copy link
Member

@TimWolla TimWolla commented Sep 18, 2025

This is useful to include the necessary files for a constant’s @cvalue from within the arginfo itself.

This is useful to include the necessary files for a constant’s `@cvalue` from
within the arginfo itself.
$conds = [];
foreach ($stmts as $stmt) {
$cond = self::handlePreprocessorConditions($conds, $stmt);

Copy link
Member

Choose a reason for hiding this comment

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

I don't think using declare() is the right approach here, it adds a new declaration in stubs that isn't valid in normal PHP code, meaning that stubs would no longer be valid PHP:

Warning: Unsupported declare 'c_include' in /in/oj65h on line 3

can I suggest instead just using a C preprocessor macro, #include <stdint.h>
this would be a comment, so it would get skipped in the next block, and you would just add handling to handlePreprocessorConditions to ensure that for #include a new IncludeInfo is added (make the handlePreprocessorConditions method non-static)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree that this is somewhat abusing the existing PHP syntax.

Copy link
Member Author

Choose a reason for hiding this comment

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

meaning that stubs would no longer be valid PHP:

This is just a warning. It's valid PHP code.

can I suggest instead just using a C preprocessor macro,

I initially tried that, but it got pretty ugly: The existing logic to handle #if / #endif is “statement-based”. Since the #include would not be a statement, special handling would be required.

Also the declare nicely forces the #include to appear at the top of the file, avoiding random includes from appearing somewhere in the middle of the stub.

$generatedFuncInfos = [];

$argInfoCode = generateCodeWithConditions(
$fileInfo->includeInfos, "\n",
Copy link
Member

Choose a reason for hiding this comment

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

we don't need both a "\n" at the end of each line and a "\n" when combining them, that leads to blank lines between the inclusions

#if 0
declare(
c_include='<stdint.h>',
c_include='"zend_attributes.h"'
Copy link
Member

Choose a reason for hiding this comment

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

My 2 cents: why I'm not enthusiastic about this feature is that it would add even more C code in stubs. For ifdefs and a few constant values it was unavoidable, but these includes are different: one should decide if they need a particular include or not, or which includes they want to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

This one in test.stub.php is just to test that the functionality works with both include syntaxes and that the preprocessor checks also work. My use case is including the necessary headers for @cvalue, such that the files including the _arginfo don't need to know which constants are required by the various register_*() functions, particularly when the same _arginfo is required in multiple files.

zend_attributes.h should just automatically included by the stubs when attributes are used to make them self-contained. It's incredibly annoying to manually include it when using deprecations.

@bwoebi
Copy link
Member

bwoebi commented Sep 26, 2025

I'm not a big fan of this. Let's have the files included by the code file including the arginfo file and keep the stub files clean.

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