Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Non-pure default arguments are mistakenly cached #9965

Closed
@iluuu1994

Description

@iluuu1994

Description

PHP compiles function default arguments to constant ASTs. The AST is evaluated when the function is called. When the result of the evaluation is a non-refcounted value, PHP assumes that the AST is pure (will always evaluate to the same value) and will then cache the value and skip re-evaluation in the next function call. This assumption is incorrect.

<?phpclass Foo {publicfunction__toString() {static$i =0;return (string)$i++;    }}functiontest(string$foo =newFoo() .'') {var_dump($foo);}test();test();test();

Resulted in this output:

string(1) "0"string(1) "0"string(1) "0"

But I expected this output instead:

string(1) "0"string(1) "1"string(1) "2"

Instead what should be done is evaluation of the AST should report whether the AST was pure or not. This currently mainly depends on whethernew was used.

PHP Version

PHP 8.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp