php / php/php-src

Wrong line & file on error trace

Open
#18,105 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
definitions.php
<?php

class ThrowableParam {
	
   public function __construct() {
		
       // this will be line #7 for definitions.php:
      throw new Exception(sprintf('I expect to indicate file %s on line %s but it throws', basename(__FILE__), __LINE__));
		
   }
	
}

trait TraitInASeparateFile {

    // but this will be line #16 for definitions.php:		
    public function execute(ThrowableParam $param=new ThrowableParam): void {}
	
}

?>
main.php
<?php

include './definitions.php';

class Foo  {

    use TraitInASeparateFile;

}

$bar=new Foo;
$bar->execute(); // line #11 for main.php

// So, there is no line #16 for main.php

?>
RESULT :

Fatal error: Uncaught Exception: I expect to indicate file definitions.php on line 7 but it throws in ./main.php:16

  Stack trace:
  #0 ./definitions.php(7): constant expression
  #1 ./definitions.php(16): ThrowableParam->__construct()
  #2 ./main/php(11): Foo->execute()
  #3 {main}
  thrown in /var/www/html/nbcloud/_tests/bugPHP.php on line 16

BUT EXPECT :

Fatal error: Uncaught Exception: I expect to indicate file definitions.php on line 7 but it throws in ./definitions.php:7

  Stack trace:
  #0 ./definitions.php(7): constant expression
  #1 ./definitions.php(16): ThrowableParam->__construct()
  #2 ./main/php(11): Foo->execute()
  #3 {main}
  thrown in /var/www/html/nbcloud/_tests/bugPHP.php on line 16

PHP Version

8.4.5

Operating System

Debian 11

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 by reproducing the report with definitions.php and main.php on PHP 8.4.5, comparing the thrown location with the stack trace. Investigate the runtime handling of the constructor's constant-expression default argument and verify that the reported throw location is definitions.php:7 rather than main.php:16.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.