Skip to content

gen_stub: arg --replace-predefined-constants on entries with several constants - #25531

Open
jordikroon wants to merge 1 commit into
php:PHP-8.6from
jordikroon:gen-stub-multi-constant-entry
Open

jordikroon wants to merge 1 commit into
php:PHP-8.6from
jordikroon:gen-stub-multi-constant-entry

Conversation

@jordikroon

@jordikroon jordikroon commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Companion to php/doc-en#6123, which documents a constant together with its aliases in a single term, as proposed in php/doc-en#5516 (comment):

<term>
 <constant xml:id="constant.zend-thread-safe">ZEND_THREAD_SAFE</constant>,
 <constant xml:id="constant.php-zts">PHP_ZTS</constant>
 (<type>bool</type>)
</term>

build/gen_stub.php --replace-predefined-constants assumed one constant per <term> / <entry>, so it could not regenerate this markup. It now handles several:

To test:

build/gen_stub.php --replace-predefined-constants . /path/to/doc-en/

@jordikroon
jordikroon marked this pull request as draft November 17, 2026 18:41
@jordikroon
jordikroon changed the base branch from master to PHP-8.6 November 17, 2026 18:41
@jordikroon
jordikroon marked this pull request as ready for review November 17, 2026 20:06
@kocsismate

Copy link
Copy Markdown
Member

I've already attempted to fix this problem the other way around a long while ago: php/doc-en#5434 Actually, Gina recommended this approach to fix the markup: php/doc-en#5516 (comment)

So instead of doing a workaround in the stubs, I'd prefer to fix the markup so that even those constant documentations can be generated that have aliases.

@jordikroon
jordikroon force-pushed the gen-stub-multi-constant-entry branch from 118705e to 8f8ef8e Compare November 21, 2026 18:29
@jordikroon

Copy link
Copy Markdown
Member Author

@kocsismate I was more focused towards fixing the error. It slipped my mind that we discussed this before. So this is a good moment to fix it.
I have changed the PR description, and updated the code. php/doc-en#6123 reflects this change.

Comment thread build/gen_stub.php
$manualConstantElement = $manualTermElement->getElementsByTagName("constant")->item(0);
$manualConstantElements = $manualTermElement->getElementsByTagName("constant");
$manualConstantElement = $manualConstantElements->item(0);
if (!$manualConstantElement instanceof DOMElement) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The gen_stub --verify-manual now reports some constants as missing which are in in fact documented. As far as I can see, they appear in a row as a 2nd item. E.g.:

Warning: Missing predefined constant for Dom\INDEX_SIZE_ERR

Comment thread build/gen_stub.php
$element->appendChild($constantElement);
foreach ($manualConstantElements as $i => $manualConstantElement) {
$constantElement = $doc->createElement("constant");
$constantElement->textContent = $manualConstantElement->textContent;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about using cloneNode() here instead of the manual element reconstruction (which was even more incomplete before)?

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.

2 participants