php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28167 Stack trace and a static method
Submitted: 2004-04-26 20:37 UTC Modified: 2004-10-13 09:20 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: jaguargordon at free dot fr Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2004-04-26 (dev) OS: Windows XP SP1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jaguargordon at free dot fr
New email:
PHP Version: OS:

 

 [2004-04-26 20:37 UTC] jaguargordon at free dot fr
Description:
------------
The stack trace feature seams to mishandle static methods when a exception is raised.

Reproduce code:
---------------
<pre><?php

class MyException extends Exception {
function raise() {
throw new MyException;
}

static function raiseStatic() {
throw new MyException;
}
}

function dontwork() { return false; }

class Foo {
function bar() {
$v = @dontwork() or MyException::raise();
}

function barStatic() {
$v = @dontwork() or MyException::raiseStatic();
}
}

$foo = new Foo;

try { $foo->bar(); }
catch( Exception $e ) { echo $e; echo "\n\n"; }

try { $foo->barStatic(); }
catch( Exception $e ) { echo $e; echo "\n\n"; }

?></pre>

Expected result:
----------------
exception 'MyException' in C:\www\static.php:6
Stack trace:
#0 C:\www\static.php(19): MyException::raise()
#1 C:\www\static.php(29): Foo->bar()
#2 {main}

exception 'MyException' in C:\www\static.php:10
Stack trace:
#0 C:\www\static.php(23): MyException::raiseStatic()
#1 C:\www\static.php(32): Foo->barStatic()
#2 {main}


Actual result:
--------------
exception 'MyException' in C:\www\static.php:6
Stack trace:
#0 C:\www\static.php(19): Foo->raise()
#1 C:\www\static.php(29): Foo->bar()
#2 {main}

exception 'MyException' in C:\www\static.php:10
Stack trace:
#0 C:\www\static.php(23): MyException::raiseStatic()
#1 C:\www\static.php(32): Foo->barStatic()
#2 {main}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-26 20:41 UTC] jaguargordon at free dot fr
title ...
 [2004-10-13 02:05 UTC] php at bobsilva dot com
Not sure this is a bug.
The Relection API is dependent on the class definition not the usage of the class. Therefore, since the raise() method is only called statically and not defined as static, it properly indicates this in the stack trace. In PHP5, calling non-static methods statically is only a BC option and therefore should not be used.
 [2004-10-13 09:20 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Correct analysis, no bug here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 17:01:36 2024 UTC