Skip to content

Recursion protection for deprecation constants not released on bailout #18463

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

Open
DanielEScherzer opened this issue Apr 29, 2025 · 0 comments
Open

Comments

@DanielEScherzer
Copy link
Member

Description

The following code:

<?php

function handler($errno, $errstr, $errfile, $errline) {
	echo "$errstr in $errfile on line $errline\n";
	eval('class string {}');
}

set_error_handler( 'handler' );

var_dump( _ZendTestClass::ZEND_TEST_DEPRECATED );

Invoked with php --repeat 2 /var/www/html/test.php
Resulted in this output:

Executing for the first time...
Constant _ZendTestClass::ZEND_TEST_DEPRECATED is deprecated in /var/www/html/test.php on line 10

Fatal error: Cannot use "string" as a class name as it is reserved in /var/www/html/test.php(5) : eval()'d code on line 1
Finished execution, repeating...
int(42)

But I expected this output instead:

Executing for the first time...
Constant _ZendTestClass::ZEND_TEST_DEPRECATED is deprecated in /var/www/html/test.php on line 10

Fatal error: Cannot use "string" as a class name as it is reserved in /var/www/html/test.php(5) : eval()'d code on line 1
Finished execution, repeating...
Constant _ZendTestClass::ZEND_TEST_DEPRECATED is deprecated in /var/www/html/test.php on line 10

Fatal error: Cannot use "string" as a class name as it is reserved in /var/www/html/test.php(5) : eval()'d code on line 1

Caused by the recursion protection (CONST_RECURSIVE flag) not getting removed because the user handler triggers a bailout. Should only apply to internal constants because userland constants aren't in the persistent memory and so would get recreated on a new request anyway

Also affects non-class constants on master following #16952
Relates to #17712

PHP Version

PHP 8.4 @ e18498e
PHP master @ 26dbcb7

Operating System

No response

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Apr 29, 2025
Internal constants are persisted; if a user error handler triggers bailout
before the recursion flag is removed then a subsequent request (e.g. with
`--repeat 2`) will start with that flag already applied.

Internal constants can presumably be trusted not to use deprecation messages
that come from recursive attributes.
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Apr 29, 2025
Internal constants are persisted; if a user error handler triggers bailout
before the recursion flag is removed then a subsequent request (e.g. with
`--repeat 2`) will start with that flag already applied.

Internal constants can presumably be trusted not to use deprecation messages
that come from recursive attributes.
iluuu1994 added a commit that referenced this issue Apr 30, 2025
This reverts commit 272f7f7.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Apr 30, 2025
Add recursion protection when emitting deprecation warnings for class
constants, since the deprecation message can come from an attribute that is
using the same constant for the message, or otherwise result in recursion.

But, internal constants are persisted, and thus cannot have recursion
protection. Otherwise, if a user error handler triggers bailout before the
recursion flag is removed then a subsequent request (e.g. with `--repeat 2`)
would start with that flag already applied. Internal constants can presumably
be trusted not to use deprecation messages that come from recursive attributes.

Fixes phpGH-18463
Fixes phpGH-17711
@DanielEScherzer DanielEScherzer changed the title Recursion protection for deprecation constants not released on bailout Reapply GH-17712 with a fix for internal class constants Apr 30, 2025
@DanielEScherzer DanielEScherzer changed the title Reapply GH-17712 with a fix for internal class constants Recursion protection for deprecation constants not released on bailout Apr 30, 2025
SakiTakamachi pushed a commit that referenced this issue May 1, 2025
This reverts commit 272f7f7.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant