php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64239 Debug backtrace changed behavior since 5.4.10 or 5.4.11
Submitted: 2013-02-18 20:48 UTC Modified: 2013-03-21 08:17 UTC
Votes:3
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kusmierz at o2 dot pl Assigned: dmitry
Status: Closed Package: *General Issues
PHP Version: 5.4.11 OS: Ubuntu,Debian,Windows
Private report: No CVE-ID:
 [2013-02-18 20:48 UTC] kusmierz at o2 dot pl
Description:
------------
The debug_backtrace behavior has been changed since 5.4.9. Previously first method 
in backtrace array was an alias name (Bmethod in my example) which seems to be ok 
as only one possibility to check name of trait's aliased method name (see also 
#61033). Now it returns trait's method name (t2method), which is incorrect in my 
mind - I can't now check which method was originally called.

Test script:
---------------
class A {
	use T1;
	public function test() { $this->backtrace(); }
}
class B {
	use T2 { t2method as Bmethod; }
}
trait T1 {
	protected function backtrace() {
		$b = new B();
		$b->Bmethod();
	}
}
trait T2 {
	public function t2method() {
		var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1));
	}
}
$a = new A(); $a->test();

Expected result:
----------------
// php 5.4.9
array(1) {
  [0]=>
  array(5) {
    ["file"]=>
    string(24) "/home/adam/test/test.php"
    ["line"]=>
    int(25)
    ["function"]=>
    string(7) "Bmethod" // OK;
    ["class"]=>
    string(1) "B"
    ["type"]=>
    string(2) "->"
  }
}

Actual result:
--------------
// php 5.4.11
array(1) {
  [0] =>
  array(5) {
    'file' =>
    string(19) "/home/adam/test.php"
    'line' =>
    int(25)
    'function' =>
    string(8) "t2method" // !
    'class' =>
    string(1) "B"
    'type' =>
    string(2) "->"
  }
}


Patches

bug64239-2.patch (last revision 2013-03-21 09:06 UTC) by dmitry@php.net)
bug64329.patch (last revision 2013-03-21 08:18 UTC) by laruence@php.net)
bug64239.patch (last revision 2013-03-21 06:04 UTC) by laruence@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-19 04:14 UTC] laruence@php.net
-Assigned To: +Assigned To: dmitry
 [2013-02-19 04:14 UTC] laruence@php.net
seems due to the new implemention of trait, not only debug_backtrace, I think the 
reflection is also affected.

dmitry, do you think this should be fixed?

thanks
 [2013-02-19 07:11 UTC] dmitry@php.net
Laruence, you are right. Reflection, debug_backtrace() and get_class_methods() are affected.

It would be good to fix it, however, I don't see a good way to do it, and I don't like to introduce a new hack. (e.g. resolving alias name by looking into hash table key).

Actually we have the same situation with class aliases.

In general, we can fix it in 5.5 using some inefficient way (e.g. add op_array->alias_function_name)

Any ideas are welcome.
 [2013-02-19 08:43 UTC] laruence@php.net
yes, that alias name gave us too many pains :)...

add a new alias_name is a easy and clear way. 

thanks
 [2013-02-19 09:04 UTC] kusmierz at o2 dot pl
Or please add magic constant, ie. __ALIASSED_METHOD__ or something (#61033)... The 
backtrace code is just workaround for me in this case.
 [2013-02-19 10:05 UTC] dmitry@php.net
Personally, I would remove traits at all :(
Of course, it's not a case, but we hardly ever going to introduce new trait related magic in 5.4.*
 [2013-03-20 07:00 UTC] laruence@php.net
an idea is search the function in ce->function table to get the lowercase alias 
name, then search in ce->traits_aliases for the origin function name,

patch will be attached, but it will definitely slowdown the debug_backtrace.
 [2013-03-21 06:04 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug64239.patch
Revision:   1363845872
URL:        https://bugs.php.net/patch-display.php?bug=64239&patch=bug64239.patch&revision=1363845872
 [2013-03-21 08:01 UTC] dmitry@php.net
I've added another patch (bug64239-2.patch), but it's incorrect anyway :(

Test script:
---------------
<?php
class A {
	public function test() {}
}
class B {
	use T2 { t2method as Bmethod; }
}
trait T2 {
	public function t2method() {
		debug_print_backtrace();
	}
}
$b = new B();
$b->t2method();
$b->Bmethod();

Expected result:
----------------
#0  B->t2method() called at [test.php:14]
#0  B->Bmethod() called at [test.php:15]

Actual result:
--------------
#0  B->Bmethod() called at [test.php:14]
#0  B->Bmethod() called at [test.php:15]
 [2013-03-21 08:18 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug64329.patch
Revision:   1363853908
URL:        https://bugs.php.net/patch-display.php?bug=64239&patch=bug64329.patch&revision=1363853908
 [2013-03-21 08:19 UTC] laruence@php.net
new patch attached, which fixed that issue you mentioned
 [2013-03-21 09:06 UTC] dmitry@php.net
The following patch has been added/updated:

Patch Name: bug64239-2.patch
Revision:   1363856795
URL:        https://bugs.php.net/patch-display.php?bug=64239&patch=bug64239-2.patch&revision=1363856795
 [2013-03-21 13:10 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2013-03-21 13:10 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7dce0194c815cdc75a780b6471660042aed7bd7a
Log: Fixed bug #64239 (Debug backtrace changed behavior since 5.4.10 or 5.4.11)
 [2013-03-21 13:11 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7dce0194c815cdc75a780b6471660042aed7bd7a
Log: Fixed bug #64239 (Debug backtrace changed behavior since 5.4.10 or 5.4.11)
 [2013-03-21 13:11 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7dce0194c815cdc75a780b6471660042aed7bd7a
Log: Fixed bug #64239 (Debug backtrace changed behavior since 5.4.10 or 5.4.11)
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 05:03:19 2014 UTC