Skip to content

Invalid error line in Fatal Error message #19081

Closed

Description

@HardlinePeak

Description

The following code:

<?php
class Test {
    public function __construct(
        public callable $example
    ) {}
}

Resulted in this output:

Fatal error: Property Test::$example cannot have type callable in /in/XWh84 on line 3

But I expected this output instead:

Fatal error: Property Test::$example cannot have type callable in /in/XWh84 on line 4

PHP Version

PHP 8.2.0 - 8.2.29, 8.3.0 - 8.3.23, 8.4.1 - 8.4.10

Operating System

No response

Activity

  1. SakiTakamachi commented on Jul 10, 2025

    @SakiTakamachi
    Member

    In this case, the relevant syntactic construct spans multiple lines starting from line 3, and the error message reports line 3, which is the starting line of that construct. Therefore, this is by design and not a bug.

    This behavior is deeply tied to the behavior of the AST, so it's not something that can be easily changed.
    If you are determined to request a change to this behavior, it is recommended to submit your opinion to the internal mailing list.

    Thank you.

  2. iluuu1994 commented on Jul 10, 2025

    @iluuu1994
    Member

    Not sure this is accurate. We have the information in the AST, but we don't update CG(zend_lineno) to adjust the position in the error message.

    diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
    index f3f6d1b75ae..c0247b48c61 100644
    --- a/Zend/zend_compile.c
    +++ b/Zend/zend_compile.c
    @@ -7683,6 +7683,8 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
     		uint32_t property_flags = param_ast->attr & (ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_READONLY | ZEND_ACC_FINAL);
     		bool is_promoted = property_flags || hooks_ast;
     
    +		CG(zend_lineno) = param_ast->lineno;
    +
     		znode var_node, default_node;
     		uint8_t opcode;
     		zend_op *opline;

    This seems to work.

  3. SakiTakamachi commented on Jul 10, 2025

    @SakiTakamachi
    Member

    @iluuu1994

    Thank you.
    Do you think this should be considered a bug?

  4. iluuu1994 commented on Jul 10, 2025

    @iluuu1994
    Member

    No, but a feature request (i.e. master) should be fine.

  5. self-assigned this
    on Jul 11, 2025
  6. added a commit that references this issue on Jul 11, 2025
    c019674
  7. added a commit that references this issue on Jul 12, 2025
    9460dbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions