php / php/php-src

call_user_func special function optimization unsound with strict_types

Open
#18,591 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: Engine Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied PHP 8.3+ reproducer and compare the namespaced and fully qualified call_user_func paths under strict_types=1. Trace the special-function optimization in the PHP interpreter, then make the behavior consistent and add coverage for both calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.