Skip to content

call_user_func special function optimization unsound with strict_types #18591

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
nielsdos opened this issue May 18, 2025 · 2 comments
Open

Comments

@nielsdos
Copy link
Member

Description

The following code:

<?php
declare(strict_types=1);

namespace Foo;

// strlen() will be called with strict_types=0, so this is legal.
var_dump(call_user_func('strlen', false));

// Called with strict_types=1
var_dump(\call_user_func('strlen', false));

Resulted in this output:

int(0)

Fatal error: Uncaught TypeError: strlen(): Argument #1 ($string) must be of type string, false given in /in/bcCZ4:10
Stack trace:
#0 /in/bcCZ4(10): strlen(false)
#1 {main}
  thrown in /in/bcCZ4 on line 10

But I expected this output instead:

Well, not sure, it should be consistent I suppose

PHP Version

8.3+

Operating System

No response

@mvorisek
Copy link
Contributor

present since eternity - https://3v4l.org/kqsCu

IMO the 1st behaviour is more correct is sense how strict_types are handled in other functions.

@Girgias
Copy link
Member

Girgias commented May 19, 2025

No, the consistent way is to use weak mode. As it is the engine performing the function call and those are always in weak mode.

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

3 participants