Skip to content
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

OPcache bypasses the user-defined error handler for deprecations #17422

Open
dtdesign opened this issue Jan 9, 2025 · 1 comment
Open

OPcache bypasses the user-defined error handler for deprecations #17422

dtdesign opened this issue Jan 9, 2025 · 1 comment

Comments

@dtdesign
Copy link

dtdesign commented Jan 9, 2025

Description

The OPcache bypasses the user-defined error handler for deprecations for the first request with a cold cache. This happens regardless of opcache.record-warnings which only has an impact on all following requests. Enabling opcache.record-warnings will yield the expected behavior for every request after the first one which populated the cache.

This does not happen when OPcache is disabled, it will behave properly for every request.

test.php

<?php

set_error_handler(static fn (...$params) => var_dump($params));

require "./dependency.php";

implicitly_nullable_parameter(new stdClass());

dependency.php

<?php
function implicitly_nullable_parameter(stdClass $foo = null) {
    echo "Called\n";
}

This can be reproduced on a web server whenever opcache_reset() reset is invoked but for simplicity this was also verified to be triggered via CLI (thanks to @TimWolla for this suggestion):

$> php -dopcache.enable_cli=1 --repeat 2 test.php
Executing for the first time...
PHP Deprecated:  implicitly_nullable_parameter(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in /opt/homebrew/var/www/test/opcache-deprecations/dependency.php on line 2

Deprecated: implicitly_nullable_parameter(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in /opt/homebrew/var/www/test/opcache-deprecations/dependency.php on line 2
Called
Finished execution, repeating...
Called
$> php --version
PHP 8.4.2 (cli) (built: Dec 17 2024 15:31:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.2, Copyright (c), by Zend Technologies

(Note: There is a bonus bug hiding here, the deprecation message is printed twice. However, the first message starts with PHP Deprecated: (…) but the second message only reads Deprecated: (…).)

The script was also invoked manually via CLI without OPcache to verify that the behavior is identical to FPM:

$> php test.php
array(4) {
  [0]=>
  int(8192)
  [1]=>
  string(141) "implicitly_nullable_parameter(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead"
*snip*

PHP Version

PHP 8.4.2

Operating System

macOS 15.1.1

@TimWolla
Copy link
Member

OPcache explicitly clears the user error handler in:

ZVAL_UNDEF(&EG(user_error_handler));

before compiling the file. This is done since the first version of the open source OPcache, so it's not clear to me, why it does this.

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

2 participants